[cfe-commits] Fwd: Clang fails to compile code that works with gcc on windows due to wint_t not defined

Ahmed Badran ahmed.badran at gmail.com
Mon Jul 12 03:28:43 PDT 2010


Hi,

I'm not sure if this is related to
http://llvm.org/bugs/show_bug.cgi?id=7571mentioned in the thread
"[PATCH] 7571: stddef.h and wint_t".
I sent it to cfe-dev and have not gotten any opinions about whether this is
the right fix. I thought I'd send it to cfe-commits for review. If you think
that's the right solution, I have a patch attached.

Regards,
Ahmed


---------- Forwarded message ----------
From: Ahmed Badran <ahmed.badran at gmail.com>
Date: Fri, Jul 9, 2010 at 7:45 PM
Subject: Clang fails to compile code that works with gcc on windows due to
wint_t not defined
To: cfe-dev at cs.uiuc.edu


Hi,

I am trying to use clang to compile a very simple hello world on Windows
and compilation is failing due to wint_t not being defined.

Here are the particulars of my environment, I am trying it on Cygwin,
with versions of llvm & clang that are a couple days old. I've checked
out the copies and manually compiled and installed them on Cygwin (so
they are not native Windows builds).

After tracing through the header files I came to the fragments that
actually define wint_t:


>From Gcc's stddef.h:

#if defined (__need_wint_t)
#ifndef _WINT_T
#define _WINT_T

#ifndef __WINT_TYPE__
#define __WINT_TYPE__ unsigned int
#endif
typedef __WINT_TYPE__ wint_t;
#endif
#undef __need_wint_t
#endif


In clang's stddef.h, the equivalent is:

// Some C libraries expect to see a wint_t here. Others (notably MinGW)
will use
// __WINT_TYPE__ directly; accomodate both by requiring __need_wint_t
#if defined(__need_wint_t) && !defined(_WINT_T)
#define _WINT_T
typedef __WINT_TYPE__ wint_t;
#endif


Now, what's happening is that through the inclusion chain, Gcc's
stddef.h is included multiple times, each time sort of enabling an extra
part of the file, while clang's stddef.h is included only once at the
very beginning through stdio.h before __need_wint_t is defined. Later on
when __need_wint_t actually gets defined and stddef.h is included again,
the guard directive prevents it from being read and thus wint_t never
gets defined.

I'm not sure what's the best way to solve this problem. I do not want to
go and start locally hacking the include files, I know they will change
down the road and thus whatever will compile after my hacks will break
again in the future.

I have attached the following formatted patch, if you guys think that's
a valid solution, I'll go ahead and send if to the cfe-commits list for
review.

+#if (!defined(__STDDEF_H) || defined(__need_wint_t))
 #ifndef __STDDEF_H
 #define __STDDEF_H
+#endif


Regards,
Ahmed
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20100712/2dc7e2a8/attachment.html>
-------------- next part --------------
--- llvm/tools/clang/lib/Headers/stddef.h	2010-07-08 13:05:11.112124500 -0700
+++ llvm-hacks/tools/clang/lib/Headers/stddef.h	2010-07-09 19:35:02.310076000 -0700
@@ -23,8 +23,10 @@
  *===-----------------------------------------------------------------------===
  */
 
+#if (!defined(__STDDEF_H) || defined(__need_wint_t))
 #ifndef __STDDEF_H
 #define __STDDEF_H
+#endif
 
 typedef __typeof__(((int*)0)-((int*)0)) ptrdiff_t;
 #ifndef _SIZE_T


More information about the cfe-commits mailing list