[comp.sys.apollo] definition of __STDC__

rfg@NCD.COM (Ron Guilmette) (09/13/90)

In article <847@usage.csd.unsw.oz.au> cameron@spectrum.cs.unsw.oz.au (Cameron Simpson) writes:
>... __STDC__ is also evasive - they define it to 0.

Apparently, more than one C compiler does this.

Question:  Does a compiler-supplied definition of __STDC__ to `0' (rather than
`1') make the implementation non-conforming?

Another question: In other postings about the Apollo compiler, I see that
Apollo decided to define __STDCPP__.  (My belief is that __STDC__ should
imply this, but that's not important at the moment.)  What I'd like to
know is this.  Is there any similar convention for specifying that a given
implementation is a *hosted* implementation?

I needed to invent such a symbol in order to compile some code for some
operating system which didn't have all of the required header files.
I was using the GNU C compiler, which (quite rightly) defines __STDC__
because (all by itself) it constitutes a *non-hosted* (standalone?)
implementation of standard C.  Now I didn't want to try to get __STDC__
undefined (which would make my programs non-conforming in any case)
because of cases like:

	#ifdef __STDC__
	#define A_TAIL(a) foobar##a
	#else
	/* do it the old way */
	#define A_TAIL(a) foobar/**/a
	#endif

not to mention allowing for const, volatile, etc. in various places.  So
I wanted/needed to leave __STDC__ defined, but I had trouble with stuff
like:

	#ifdef __STDC__
	#include <stddef.h>
	#endif

because this was a *non-hosted* implementation.  I ended up defining my
own symbol, and using it as necessary, e.g.:

	#ifdef __HOSTED_STDC__
	#include <stddef.h>
	#endif

Was that a good idea?  What do other people do in such cases?
-- 

// Ron Guilmette  -  C++ Entomologist
// Internet: rfg@ncd.com      uucp: ...uunet!lupine!rfg
// Motto:  If it sticks, force it.  If it breaks, it needed replacing anyway.