duplicate FILE typedef, stdio.h and wchar.h

Craig Howland howland@LGSInnovations.com
Thu Mar 5 11:26:00 GMT 2015


On 03/04/2015 05:07 AM, Corinna Vinschen wrote:
> Hi Craig,
>
> On Mar  3 23:05, Craig Howland wrote:
>>       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.)
> I'm rather puzzled by this observation.  As you may imagine, these files
> are used for a long time in packages in the Cygwin distro, and if GCC
> would error out in this simple case, we had a lot of complaints from
> Cygwin package maintainers.  So the first question is, in which scenario
> do you see this problem?  I created an STC:
>
> --8<---------------cut here---------------start------------->8---
> #include <wchar.h>
> #include <stdio.h>
>
> extern FILE *foo (FILE *);
>
> int main ()
> {
>    FILE *fp = foo (NULL);
>    if (fp)
>      foo (fp);
>    return 0;
> }
> --8<---------------cut here---------------end--------------->8---
>
> and gcc -c -g -O2 -Wall does not error out, nor does it even produce
> a warning.  Same when reordering the includes.  Not even with -ansi.
I was quite surprised, too, but it's doing it (gcc 4.4.7 under RHEL6).  I 
fiddled with options a little to no avail, but decided it was easier to just fix 
it.
> I like it.  Please apply.  Alternatively we'd split out shared
> definitions like this into extra files under some directory like "bits",
> as glibc does, but it seems a lot of error-prone reshuffling effort.
>
I don't have permissions to write, so someone has to do it for me.



More information about the Newlib mailing list