copx wrote:
Is there are standard way to detect which C standard is supported by the
compiler?
I mean for conditional compilation like:
#if defined(C99)
# include "stdint.h"
#endif
The 1989 Standard defines the __STDC__ predefined macro, this must be 1
on a conforming implementation. Amendment 1 to the 1989 Standard also
defines the predefined macro __STDC_VERSION__ which will be 199409L for
C89 Amendment 1 and 199901L for C99. You can use these two macros to
determine what version your implementation purportedly conforms to:
#include <stdio.h>
#if defined(__STDC__)
# if __STDC_VERSION__ >= 199901L
# define VERSION "C99 or greater"
# elif __STDC_VERSION__ >= 199409L
# define VERSION "C89 with Amendment 1"
# else
# define VERSION "C89"
# endif
#else
# define VERSION "Pre-C89"
#endif
int main (void) {
puts(VERSION);
return 0;
}
$ gcc -Wall -W -ansi -pedantic print_standard_version.c -o
print_standard_version
$ ./print_standard_version
C89
$ gcc -Wall -W -std=iso9899:199409 -pedantic print_standard_version.c
-o \
print_standard_version
$ ./print_standard_version
C89 with Amendment 1
$ gcc -Wall -W -std=c99 -pedantic print_standard_version.c -o
print_standard_version
$ ./print_standard_version
C99 or greater
Robert Gamble