Machine specific predefined names

Karl Heuer karl at haddock.ISC.COM
Fri Feb 19 05:23:17 AEST 1988


In article <1988Feb17.115402.12739 at light.uucp> bvs at light.UUCP (Bakul Shah) writes:
>Now our local stdc expert says that [names like "am29k" are in the user's
>namespace].  He suggests that ANSII C compilers for the AMD29000 processor
>predefine _Am29k (for this family) and _Am29000 (for this specific
>processor).  [But these are hard to type.]

>So my questions are
>1) Is our local expert right?

Yes.

>2) If so, will companies such as SUN, AT&T, DEC etc. predefine
>   names such as _Sparc, _U3b2, _Vax in their ANSII C compilers?
>   Note that doing so will also force change in some `existing
>   practices'.

If they want them to be conforming compilers, they will change the predefined
names.  I doubt that mixed-case names like "_Vax" will be used; either "__vax"
or "_VAX" seems better to me.  Another proposal I've seen is to standardize
prefixes within this namespace, e.g. "__OS_unix" and "__MACH_vax".

>I also wonder about exactly where the user / implementer boundary
>falls.  If the compiler vendor provides a system call library, is
>it considered part of an implementation?  If so, will the system
>calls have to be _Renamed?  This doesn't make sense to me.
>Clearly, I am missing something here.

The proper way to provide a non-ANSI function like "fork" is to make an entry
point named "_fork" (single underscore is sufficient here; it's an external
identifier).  The system() function, which is part of the ANSI library, should
use this name: "pid = _fork();".  Thus, system() will work properly even if
the user's program has its own global object named "fork".

The implementation may now provide, for the user's use, an entry point named
"fork" which is equivalent$ to "_fork".  This function only gets linked if the
user uses it.

>PPS: It would be neat if atleast the ANSII compilers were to
>     follow a more regular predefine scheme, something like:
>
>#define OS_TYPE                 unix

But you can't say "#if OS_TYPE == unix", or anything equivalent to it, without
making substantial changes to the preprocessor.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint
________
$ Such equivalence may be implemented by having fork() call _fork() as a
function, or a direct jump in assembly language, or by duplicating the code.
Even "#define fork _fork" might be legal, in a special <unix.h> header.



More information about the Comp.lang.c mailing list