This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
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, libc/stdlib/btowc.c.) 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> [function] 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 indirect. 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 standards.) Craig
Index: libc/include/stdio.h =================================================================== RCS file: /cvs/src/src/newlib/libc/include/stdio.h,v retrieving revision 1.74 diff -p -u -r1.74 stdio.h --- libc/include/stdio.h 18 Dec 2014 14:55:17 -0000 1.74 +++ libc/include/stdio.h 4 Mar 2015 02:52:51 -0000 @@ -49,7 +49,10 @@ _BEGIN_STD_C +#if !defined(__FILE_defined) typedef __FILE FILE; +# define __FILE_defined +#endif #ifdef __CYGWIN__ typedef _fpos64_t fpos_t; Index: libc/include/wchar.h =================================================================== RCS file: /cvs/src/src/newlib/libc/include/wchar.h,v retrieving revision 1.37 diff -p -u -r1.37 wchar.h --- libc/include/wchar.h 4 Feb 2015 11:02:36 -0000 1.37 +++ libc/include/wchar.h 4 Mar 2015 02:52:51 -0000 @@ -49,7 +49,10 @@ _BEGIN_STD_C /* As in stdio.h, <sys/reent.h> defines __FILE. */ +#if !defined(__FILE_defined) typedef __FILE FILE; +# define __FILE_defined +#endif /* As required by POSIX.1-2008, declare tm as incomplete type. The actual definition is in time.h. */
Attachment:
ChangeLog.FILE
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |