wint_t definition

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).

Should Clang be defining wint_t in stddef.h or is GCC at fault here (i.e. shouldn't be defining it there)? This bug shows up when configuring pkg-config's bundled glib[1]; at a high level, trying to build the bundled glib fails because some unrecognised parameters are passed to Clang. The parameters being passed to Clang were different to the ones being passed to GCC, so I had a poke around in the config.log to check for something going awry and found this issue*. Should I file a bug?

Cheers,

Andrew

* It may not be the cause of the change in parameters, but it seemed like a problem that should be fixed.

[1] pkg-config

iswalnum.c (97 Bytes)

It's hard to tell without more information. My copy of gcc (4.2) doesn't define wint_t in stddef.h. 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.

-Chris

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

Hi Andrew,

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).

I encountered the same problem recently and looked into why it was
happening. I concluded that this glibc change probably had something to
do with it:

http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=5703f4727380ca751da51a94664689b5e97dc89f

(specifically the last hunk of the diff).

Should Clang be defining wint_t in stddef.h or is GCC at fault here
(i.e. shouldn't be defining it there)? This bug shows up when
configuring pkg-config's bundled glib[1]; at a high level, trying to
build the bundled glib fails because some unrecognised parameters
are passed to Clang. The parameters being passed to Clang were
different to the ones being passed to GCC, so I had a poke around in
the config.log to check for something going awry and found this
issue*. Should I file a bug?

Judging by the wording of the standard (wchar.h should be included in
wctype.h to provide wint_t, as I understand it) it looks like this is a
glibc quirk. I felt it was easier to bodge my code to include wchar.h
before wctype.h than to get this fixed but good luck to you if you
attempt to do so.

Andrew