Steven Borley - 2006-12-04

Is there a way, programatically, to tell if the compiler has been passed any one of --std-c89, --std-c99, --std-sdcc89  or --std-sdcc99, and to distinguish between them? Perhaps by a pre-defined symbol?

I had thought I should be able to use __STDC__ and __STDC_VERSION__ as follows for --std-c89 and--std-c99, but I don't seem to get sensible answers.  __STDC__ is always defined (which is reasonable), but also __STDC_VERSION__ is always 199901L (implying C99).

To test this I placed the following in my code

#ifdef __STDC__
#warning __STDC__ is defined (C89, and later)
#endif

#ifdef __STDC_VERSION__
#warning __STDC_VERSION__ is define (C90, and later)

#if __STDC_VERSION__ == 199409L
#warning __STDC_VERSION__ == 199409L (C94)
#endif

#if __STDC_VERSION__ == 199901L
#warning __STDC_VERSION__ == 199901L  (C99)
#endif

#endif

I compile with...
$ sdcc-4491/bin/sdcc -c  coreext.c -o coreext.rel
or
$ sdcc-4491/bin/sdcc -c  --std-c89 coreext.c -o coreext.rel
or
$ sdcc-4491/bin/sdcc -c  --std-c99 coreext.c -o coreext.rel

And I always get ...
coreext.c:36:2: warning: #warning __STDC__ is defined (C89, and later)
coreext.c:40:2: warning: #warning __STDC_VERSION__ is define (C90, and later)
coreext.c:47:2: warning: #warning __STDC_VERSION__ == 199901L (C99)

Am I simply misunderstaning the use of these pre-defined symbols?

Regards,
steven