Yonatan Broza <shorttoedeagle@xxxxxxxxx> writes: > Any idea on why the following code fails to compile? > > Changing the order of include directives or removing one of them solves the > problem. > > Is this a bug? > > Thanks! > > BEGIN_SESSION > yb@chroot:~> cat include.cpp > #include <wchar.h> > #include <wctype.h> > #include <iostream> > > main() {} > yb@chroot:~> g++ include.cpp > In file included from /usr/include/c++/4.3/cwchar:49, > from /usr/include/c++/4.3/bits/postypes.h:47, > from /usr/include/c++/4.3/iosfwd:47, > from /usr/include/c++/4.3/ios:44, > from /usr/include/c++/4.3/ostream:45, > from /usr/include/c++/4.3/iostream:45, > from include.cpp:3: > /usr/include/c++/4.3/cstddef:55: error: ‘::ptrdiff_t’ has not been declared This is a bug. The bug appears to be in glibc. /usr/include/wctype.h does this: /* Get wint_t from <wchar.h>. */ # define __need_wint_t # include <wchar.h> /usr/include/wchar.h does this: #ifndef _WCHAR_H #if !defined __need_mbstate_t && !defined __need_wint_t # define _WCHAR_H 1 # include <features.h> #endif #ifdef _WCHAR_H ... #endif /* _WCHAR_H defined */ /* Undefined all __need_* constants in case we are included to get those constants but the whole file was already read. */ #undef __need_mbstate_t #undef __need_wint_t #endif /* wchar.h */ In other words, if you #include <wchar.h> before you #include <wctype.h>, then _WCHAR_H is already defined, and <wchar.h> does not #undef __need_wint_t. The remaining #define of __need_wint_t remains to mess up the #include of <stddef.h> which is done by <cstddef>. The problem can be seen with a straight C file: #include <wchar.h> #include <wctype.h> #include <stddef.h> ptrdiff_t i; I filed a glibc bug report: http://sourceware.org/bugzilla/show_bug.cgi?id=9694 Thanks. Ian