How can I find out cc or cpp symbols?

Gordon Burditt gordon at sneaky.UUCP
Wed May 10 07:58:20 AEST 1989


>I think Doug missed the point of the question.  Remember that the
>original discussion was about how to determine what names are defined
>in the local environment.  The question is not what to define, but

"what names are defined in the local environment" is ill-defined.

Do you mean (and I am making unwarranted assumptions about how compilers are 
invoked, but assuming "traditional UNIX compiler flags"):

a) The list of all preprocessor symbols that might be predefined under
   appropriate circumstances, excluding the effect of -D and -U flags?
b) The list of all preprocessor symbols that are predefined on THIS 
   compilation, excluding the effect of -D and -U flags (which is obviously
   undefined if there is no compilation in progress)?
c) The list of all preprocessor symbols that will always be predefined
   on ANY compilation for this compiler, excluding the effect of -D and
   -U flags?

It seems to me that what is wanted is list (a) in the compiler documentation,
along with explanations of the conditions that apply to symbols on
list (a) but not list (c).  I certainly don't want <default.h> to be
modified often ("Could you put up the default.h for nethack, please?";
"NO!  I'm in the middle of compiling something else!")

>where to define it.  As I understand the suggestion, the <default.h>
>file would contain all of the names defined in the local environment
>that weren't absolutely required by the standard.  Thus, for example on
>a Vax Unix system (using pre-ANS names), it might contain, among other
>things,
>	#define	unix	1
>	#define	vax	1
>By examining <default.h> the user could determine exactly what would be
>predefined.  It might be that there would need to be special handling

If all you want to do is READ it, it would seem sufficient to put it
in the compiler (printed) documentation.  And in that case, there would 
be no need for the compiler to read it if it were already compiled in.

>of this file, so that -U would be meaningful:  <default.h> might need
>to be read before parsing command-line arguments.  But that's no
>different than having the symbols hard-coded into the compiler (or
>pre-processor, in this case).

Many compilers predefine symbols conditionally depending on a combination
of various compiled-in defaults and compiler flags (No, I don't mean
-D and -U).  Yes, I really mean that some symbol is defined or not
depending on whether the compiler is told to use 286 instructions
on the command line, or whether the 'char' type is to default signed
or unsigned (again, changable from the command line).  Usually this
is implemented by having the front-end program pass -D flags to
the preprocessor depending on what other flags it got.


Defines based on:		Who does it:

"char" type unsigned		GNU C
Memory model			Microsoft C 5.1 (MS-DOS), Xenix/*86
CPU type within family		GNU C, Microsoft C 5.1 (MS-DOS), Xenix/*86
Floating point unit type	GNU C, ?? Sun ??
OS version/object format	Xenix/68000 System III
ANSI compatable compilation	GNU C

Compilers that do conditional predefinition:

GNU C (all versions, I think, although the degree varies)
Microsoft C 5.1 (MS-DOS)
Xenix/*86 (all versions, I think)
Xenix/68000 System III

Compilers that don't do conditional predefinition:

Vax 4.3bsd

Another thing to think about is the wierd interaction that would happen
between the -I flag and the default.h file, especially if the specified
directory has a default.h in it.  I can think of examples (cross-compilers) 
where this would be mostly beneficial, and others where it would confuse
things considerably.

_____________________________
/* default.h */
/* note wierd pragmas required to implement default.h */
# define unix 1
# define M_XENIX 1
# pragma if $cmdarg("-v") != "3" && $cmdarg("-v") != ""
# pragma if $compiled_default("strict_ansi") || $cmdarg("-pedantic")
# define __M_V7__ 1
# pragma else
# define M_V7 1
# pragma endif
# pragma else
# pragma if $compiled_default("strict_ansi") || $cmdarg("-pedantic")
# define __M_SYS3__ 1
# define __M_SYSIII__ 1
# pragma else
# define M_SYS3 1
# define M_SYSIII 1
# pragma endif
# pragma endif

/* GNU C defines this as the base file (the value of __FILE__ as it would */
/* be on the first line of source read) What value do I use for this */
/* in a file? */
# define __BASE_FILE__	"God only knows what goes here"

# pragma if $cmdarggiven("-m68881")
# define __M68881__ 1
# pragma endif

# pragma if $compiled_default("unsigned_char") || $cmdarggiven("-funsigned-char")
# define __CHAR_UNSIGNED__ 1
# pragma endif


					Gordon L. Burditt
					...!texbell!sneaky!gordon



More information about the Comp.unix.questions mailing list