Bug 9694 - Including wchar.h then wctype.h can break stddef.h
Summary: Including wchar.h then wctype.h can break stddef.h
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.8
: P2 normal
Target Milestone: ---
Assignee: Ulrich Drepper
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-29 22:02 UTC by Ian Lance Taylor
Modified: 2014-07-02 07:34 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Lance Taylor 2008-12-29 22:02:42 UTC
This simple C program fails to compile when using glibc 2.8 (I'm using gcc 4.3.0
on Fedora 9).

#include <wchar.h>
#include <wctype.h>
#include <stddef.h>
ptrdiff_t i;

The error is:

foo.c:4: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘i’

The error is because the typedef for ptrdiff_t was not defined by <stddef.h>. 
That happens because wctype.h does this:

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

Unfortunately, if the program has already #included <wchar.h>, then _WCHAR_H is
defined and <wchar.h> does nothing, including not doing a #undef of
__need_wint_t.  The presence of the __need_wint_t then causes <stddef.h> to only
define wint_t, and not define the types it should normally define when it is
included directly.

It seems to me that either wctype.h should not #include wchar.h, or wchar.h
should reliably #undef __need_wint_t.
Comment 1 Ulrich Drepper 2008-12-29 23:01:59 UTC
Changed in cvs.