Frustrated trying to be portable

Ron Guilmette rfg at NCD.COM
Sun Mar 10 18:43:56 AEST 1991


In article <15382 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
>
>In fact I am well aware of AT&T's "standalone" mode for a few commands
>such as "ls", and how they are used.  On the other hand, I don't think
>you have thought this matter through very well.  If you have an
>application that performs useful work in a "freestanding" C environment,
>it must directly access hardware registers or be linked with some...

The case that I was most concerned about (and the reason I raised the
issue of __HOSTED_STDC__) had nothing to do with embedded systems or
device registers or any low-level stuff like that.  No.  The case that
I was worried about was GCC on a Sun4 under SunOS 4.0.  In *that* (perhaps
rather common) case the compiler correctly defines __STDC__ to 1 because
the implementation meets the minimal criteria for a standalone implementation.

Now, if you are using this compiler in this environment, and you do:

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


	#ifdef __STDC__
			/* some use of `size_t' */
	#endif

you are going to get errors because although GCC is a minimally
compliant implementation of ANSI C, the environment it sits in rarely
includes a set of maximally compliant header files and libraries.

That's where having __HOSTED_STDC__ would come in handy.  If it were
defined, I could be assured that after <stdio.h> was included, I could
use the type size_t, whereas if __HOSTED_STDC__ were not defined, I might
write the code to play it safe and use something bland like `int' instead
of size_t.

I could name a few dozen more examples of places where Sun or DEC or
HP, or Motorola or Intel "system" header files (for various releases
of UNIX which these companies have made) are not quite right (or not
quite enough) to really get you up to a "complete" and "conformant"
hosted implementation of ANSI C.  So if you want more examples, just
let me know.

-- 

// Ron Guilmette  -  C++ Entomologist
// Internet: rfg at ncd.com      uucp: ...uunet!lupine!rfg
// New motto:  If it ain't broke, try using a bigger hammer.



More information about the Comp.std.c mailing list