This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

__STDC_VERSION__ is undefined in gcc-3.x?


uname -a
Linux debian-home 2.2.19 #1 Sat May 19 16:25:04 CDT 2001 i686 unknown
glibc 2.2.3

The attached c file fails to compile with:
std.c: In function `main':
std.c:5: `__STDC_VERSION__' undeclared (first use in this function)
std.c:5: (Each undeclared identifier is reported only once
std.c:5: for each function it appears in.)

using gcc -v
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0.1/specs
Configured with: /usr/src/cvs/gcc-3.0/configure --verbose --enable-threads=posix
--with-system-zlib --with-dwarf2 --enable-shared --disable-nls --enable-checking
Thread model: posix
gcc version 3.0.1 20010729 (prerelease)

The corresponding c++ file fails in the same fashion. This compiles fine with
gcc -v
Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.4/specs
gcc version 2.95.4 20010703 (Debian prerelease)

In the source for cppinit.c under 2.95-branch there appears to be a simple
test:
if (!CPP_TRADITIONAL (pfile))
  {
    cpp_install (pfile, NAME("__STDC__"),       T_STDC,  0, -1);
#if 0
    if (CPP_OPTIONS (pfile)->c9x)
      cpp_install (pfile, NAME("__STDC_VERSION__"),T_CONST, "199909L", -1);
    else
#endif
      cpp_install (pfile, NAME("__STDC_VERSION__"),T_CONST, "199409L", -1);
  }

However, gcc-3_0-branch has this in cppinit.c:
  if (CPP_OPTION (pfile, lang) == CLK_STDC94)
    _cpp_define_builtin (pfile, "__STDC_VERSION__ 199409L");
  else if (CPP_OPTION (pfile, c99))
    _cpp_define_builtin (pfile, "__STDC_VERSION__ 199901L");

Under 2.95.x this file outputs the expected 199409 and fails under gcc-3.x.
This could cause some serious miscompilation of system headers and/or other
files that depend on this macro being defined.

Both compilers claim to default to std=gnu89 (==-ansi + gnu extensions). Under
2.95.x no matter which -std=xxx I pass it always returns 199409. Under 3.x,
unless I specify one of the -std=c9x options or gnu9x __STDC_VERSION__ is 
undefined. So it appears -ansi (aka -std=c89) should not define
__STDC_VERSION__? In that case, 2.95.x is wrong? and perhaps the default for
at least the 3.x-branch should be changed to 'iso9899:199409'?

#include <stdio.h>

int main()
{
	printf("__STDC_VERSION__ = %ld\n",__STDC_VERSION__);
	return 0;
}

-- 
Gordon Sadler


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]