[cfe-dev] wint_t definition

Andrew Jeffery andrew at aj.id.au
Tue Jan 5 15:32:00 PST 2010


On 06/01/10 04:57, Chris Lattner wrote:
>
> On Jan 4, 2010, at 6:48 PM, Andrew Jeffery wrote:
>
>> Hi all,
>>
>> In playing around with Clang I came across the attached C snippet
>> which compiles with GCC but fails with Clang. This appears to be
>> because GCC defines the wint_t type in stddef.h where Clang doesn't
>> (changing the wctype.h include to wchar.h does away with the whole
>> issue: wchar_t is defined and the wint_t issue becomes non-existent).
>
> It's hard to tell without more information. My copy of gcc (4.2) doesn't
> define wint_t in stddef.h.

Hmm... so starting at the problem, in /usr/include/wctype.h I have:

/* Get wint_t from <stddef.h>.  */
# define __need_wint_t
# include <stddef.h>

Then in each stddef.h supplied with the GCCs I have installed (versions 
3.4.6, 4.3.2, 4.4.2, 
/usr/lib64/gcc/x86_64-pc-linux-gnu/<version>/include/stddef.h) there is:

#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

Granted, it is nested in #ifndef __sys_stdtypes_h (not sure exactly what 
influence this has, I don't have a deep knowledge of how this all fits 
together... Am I in the right place(s) here?)

However, it does pull in several other
> headers that it isn't supposed to, e.g.:
>
> #if defined (__FreeBSD__) && (__FreeBSD__ >= 5)
> #include <sys/_types.h>
> #endif
>
> which might pull it in. GCC's stddef.h is a real nasty mess of macros,
> it's hard to tell what you might be getting. However, in any case
> (according to C99 7.17) stddef.h isn't supposed to define wint_t, so I'd
> consider this a GCC bug.

Yeah, I found that and was then unsure exactly where the bug might be: 
GCC (for compiling the code in gnu89/gnu99/c99 when it apparently 
shouldn't), Clang (for not compiling it, as GCC does), autotools (poor 
configure test case?), glib (poor configure test case?) or pkg-config 
(bundles old glib with quite a few patches).

Cheers,

Andrew



More information about the cfe-dev mailing list