duplicate FILE typedef, stdio.h and wchar.h

Craig Howland howland@LGSInnovations.com
Wed Mar 4 10:07:00 GMT 2015

      stdio.h and wchar.h both have unconditional "typedef FILE __FILE"
declarations, which causes GCC to error out if both are included to the same
source, which happens in any number of newlib source files.  (For example,
      The issue apparently was introduced with wchar.h version 1.34 on 23
Dec 2013, when that typedef was added.  (How I managed to not run into this
error until now is a surprise.)
      The C99 standard does not specify FILE being defined in wchar.h, while
POSIX has it listed as an extension to C.  Both C and POSIX give synopses
for wide-character functions which have FILE in the prototype as:

#include <stdio.h>
#include <wchar.h>

This implicitly says that FILE should not be defined in wchar.h to avoid
duplication.  And if it were to be put in per the POSIX CX, it would
essentially always get protected out.  (Makes you wonder why POSIX added
it.  GCC certainly does not need it, as evidenced by wchar.h being fine
prior to Dec 2013 (all FILEs in wchar.h are FILE *).)
      Despite POSIX and C, Newlib source sometimes includes wchar.h first,
partly because sometimes the inclusions of one or the other of the file are
      The question is, what is the right way to address the problem? Should
it have the proper POSIX CX protection macro put on it?  (But that, in itself
would not fix the Newlib build issues that I'm seeing, since CX is often
activated, I suspect.)  Revert the addition to wchar.h?  (We got along fine
before that, but then that bit of POSIX would be lacking, even if its
desirability is questionable.)  Add duplication-protection macros to both
files, to allow both orders?  (It would work, but is probably really not
proper according to the C standard.)
      While I don't like it much, I've attached a patch for the latter
solution under the assumption that it might be the preferred choice.
      (By the way, looking at GLIBC was of no help, as they do it in a bad
way, including stdio.h in wchar.h--which is expressly forbidden by the
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FILE.patch
Type: text/x-patch
Size: 1066 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20150304/07d311b6/attachment.bin>
-------------- next part --------------
	* libc/include/stdio.h libc/include/wchar.h:  Protect FILE typedef from
	redefinition (in case both stdio.h and wchar.h are both included).

More information about the Newlib mailing list