[comp.sys.sgi] cpp reserved symbols

davis@MASIG2.OCEAN.FSU.EDU (Alan Davis) (08/09/89)

I have been trying to compile a software package from a 3rd party which was
designed to run on various machines including VAXes.  In the C code they have
inserted #ifdef vax || #ifdef vms cpp directives (amongst others) so the code
could be ported to various machines.  I was under the impression that these
were reserved symbols that had already been defined to cpp ( 3xxx IRIS,
running 3.6).  However I have just found out that vms and vax are NOT defined,
contrary to the misleading statement in the cpp man page, which states upon
closer inspection "The current list of these possibly reserved symbols
includes:".  Does any one have a complete list of "possibly reserved symbols"
that ARE currently defined?
--
          Alan Davis                |
Mesoscale Air-Sea Interaction Group | TCP/IP davis@masig1.ocean.fsu.edu
    Florida State University        |             (128.186.3.1)
    435 OSB  Meteorology Annex      | SPAN   scri::"davis@masig1.ocean.fsu.edu"
    Tallahassee, FL 32306-3041      | BITNET davis%masig1.ocean.fsu.edu@cunyvm
         (904) 644-3798             |
_______________________________________________________________________________

goss@SNOW-WHITE.MERIT-TECH.COM (Mike Goss) (08/09/89)

Regarding the message:
> From: Alan Davis <davis@masig2.ocean.fsu.edu>
> Message-Id: <8908091305.AA01742@masig2.ocean.fsu.edu>
> Subject: cpp reserved symbols
	
> I have been trying to compile a software package from a 3rd party which was
> designed to run on various machines including VAXes.  In the C code they have
> inserted #ifdef vax || #ifdef vms cpp directives (amongst others) so the code
> could be ported to various machines.  I was under the impression that these
> were reserved symbols that had already been defined to cpp ( 3xxx IRIS,
> running 3.6).  However I have just found out that vms and vax are NOT defined,
> contrary to the misleading statement in the cpp man page, which states upon
> closer inspection "The current list of these possibly reserved symbols
> includes:".  Does any one have a complete list of "possibly reserved symbols"
> that ARE currently defined?

It has been my experience that every C compiler vendor defines their own
set of symbols that you can test to see if you are using their compiler
or CPU.  The "#ifdef" ("#ifndef") directives test whether the symbol
is (is not) defined.  This is handy since C is not quite portable,
and also since the operating system is not always UNIX, and may not
support UNIX compatible system calls.

The VAX/VMS C compiler defines the
symbols "VMS" and "VAX" to allow you to test whether you are using
the VMS operating system and a VAX, respectively.  These symbols
should not (in theory) be defined on any other machine.  Most UNIX C
compilers define the symbol "unix" and/or "UNIX" to allow you to test
for the UNIX operating system.  On MS-DOS, Microsoft C defines the
symbols "MSC" and "MSDOS" to allow tests for this specific compiler
and operating system.  

Most compilers also allow tests for CPU type, as well.
On the MIPS systems (SGI 4D included), the preprocessor
defines the symbol "mips".  On some Motorola 68000 based systems, 
the symbol "M68000" is defined.
	
Unfortunately, there is no standard for these symbols.  Also, most
compiler manuals bury this information somewhere in the depths of the
appendices or worse, making it hard to track down.  I've often wished
that C compilers had some option which would cause the preprocessor
to spew out a list of all the predefined symbols.

Mike Goss
Merit Technology Inc.

ciemo@bananapc.wpd.sgi.com (Dave Ciemiewicz) (08/10/89)

In article <8908091305.AA01742@masig2.ocean.fsu.edu>, davis@MASIG2.OCEAN.FSU.EDU (Alan Davis) writes:
> includes:".  Does any one have a complete list of "possibly reserved symbols"
> that ARE currently defined [for the 3000 series]?

The predefined #defines are:

	sgi
	unix
	SVR0

For the 4D, see the cc(1) manual page for the symbols defined by cpp when
cc is invoked.


--
-------------------------------------------------------------------------------
			Cosmo Ciemo, Silicon Valley Dude

I was traipsing through the fields of my mind when I stepped in something that
smelled rather ripe.
-------------------------------------------------------------------------------

mike@BRL.MIL (Mike Muuss) (08/12/89)

The list of "possibly reserved symbols" is amazingly long.   You find
it by the experimental method, as you port code around. Some that I know
of include:

unix, vax, m68k, m68000, alliant, sel, gould, sgi, mips,
sun, sun3, sparc, apollo, CRAY, CRAY1, CRAY2, convex, ardent,
stellar, eta10, pyr.

The ANSI-C specification calls for vendor-provided symbols to begin
with an underscore and an upper-case letter.  For example, _CRAY,
_Vax, etc.  This is a good idea, but will result in a whole
new raft of symbols being defined.  Along with __STDC__.

There are other pitfalls as well, like when you need <time.h>,
when you need <sys/time.h>, and when you need both.  Arrgh!

	Best,
	 -Mike