stdio.h: broken standard compliance.

Greg Chicares
Tue Oct 11 11:44:00 GMT 2011

On 2011-10-10 18:42Z, Kaz Kylheku wrote:
> Corinna Vinschen writes:
>> > $ gcc -Wall -ansi -D_POSIX_C_SOURCE=2 posix-ansi.c
>  ^^^^^
>> fileno and pclose are *not* ANSI functions. Therefore, if you define
>> -ansi, you get the below errors. The newlib headers have explicit
>> #ifndef __STRICT_ANSI__ guards around the non-ANSI definitions.
> I do not believe that your interpretation of the applicable standards 
> is
> entirely correct.
> The -ansi flag tells the GNU *compiler* to disable its built-in
> extensions. So for instance the block evaluation syntax
> ({ expr1; ... ; exprn }) won't be available.

It does more than that:
| The macro __STRICT_ANSI__ is predefined when the -ansi option is used.
| Some header files may notice this macro and refrain from declaring
| certain functions or defining certain macros that the ISO standard
| doesn't call for; this is to avoid interfering with any programs that
| might use these names for other things.

This is a "strictly conforming program" as defined by ISO standard C:
  #include <stdio.h>
  int fileno(int x) {return 3 * x;}
  int main()        {return fileno(2);}
With '-ansi', the posix declaration of fileno() is suppressed; if it
weren't, then that program would fail to compile. See:
An argument could be made for giving _POSIX_C_SOURCE precedence over
__STRICT_ANSI__ if both are defined; but as long as that's not the
behavior, you might want to undef __STRICT_ANSI__ as appropriate.

Problem reports:
Unsubscribe info:

More information about the Cygwin mailing list