home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Elysian Archive
/
AmigaElysianArchive.iso
/
prog
/
c
/
cpp.lha
/
cpp.mem
< prev
next >
Wrap
Text File
|
1991-04-15
|
12KB
|
296 lines
1.0 C Pre-Processor
*******
* cpp *
*******
NAME: cpp -- C Pre-Processor
SYNOPSIS:
cpp [-options] [infile [outfile]]
DESCRIPTION:
CPP reads a C source file, expands macros and include
files, and writes an input file for the C compiler. If
no file arguments are given, CPP reads from stdin and
writes to stdout. If one file argument is given, it
will define the input file, while two file arguments
define both input and output files. The file name "-"
is a synonym for stdin or stdout as appropriate.
The following options are supported. Options may be
given in either case.
-C If set, source-file comments are written
to the output file. This allows the
output of CPP to be used as the input to
a program, such as lint, that expects
commands embedded in specially-formatted
comments.
-Dname=value Define the name as if the programmer
wrote
#define name value
at the start of the first file. If
"=value" is not given, a value of "1"
will be used.
On non-unix systems, all alphabetic text
will be forced to upper-case.
-E Always return "success" to the operating
system, even if errors were detected.
Note that some fatal errors, such as a
missing #include file, will terminate
CPP, returning "failure" even if the -E
option is given.
Page 2
cpp C Pre-Processor
-Idirectory Add this directory to the list of
directories searched for #include "..."
and #include <...> commands. Note that
there is no space between the "-I" and
the directory string. More than one -I
command is permitted. On non-Unix
systems "directory" is forced to
upper-case.
-N CPP normally predefines some symbols
defining the target computer and
operating system. If -N is specified,
no symbols will be predefined. If -N -N
is specified, the "always present"
symbols, __LINE__, __FILE__, and
__DATE__ are not defined.
-Stext CPP normally assumes that the size of
the target computer's basic variable
types is the same as the size of these
types of the host computer. (This can
be overridden when CPP is compiled,
however.) The -S option allows dynamic
respecification of these values. "text"
is a string of numbers, separated by
commas, that specifies correct sizes.
The sizes must be specified in the exact
order:
char short int long float double
If you specify the option as "-S*text",
pointers to these types will be
specified. -S* takes one additional
argument for pointer to function (e.g.
int (*)())
For example, to specify sizes
appropriate for a PDP-11, you would
write:
c s i l f d func
-S1,2,2,2,4,8,
-S*2,2,2,2,2,2,2
Note that all values must be specified.
-Uname Undefine the name as if
#undef name
were given. On non-Unix systems, "name"
will be forced to upper-case.
Page 3
cpp C Pre-Processor
-Xnumber Enable debugging code. If no value is
given, a value of 1 will be used. (For
maintenence of CPP only.)
PRE-DEFINED VARIABLES:
When CPP begins processing, the following variables will
have been defined (unless the -N option is specified):
Target computer (as appropriate):
pdp11, vax, M68000 m68000 m68k
Target operating system (as appropriate):
rsx, rt11, vms, unix
Target compiler (as appropriate):
decus, vax11c
The implementor may add definitions to this list. The
default definitions match the definition of the host
computer, operating system, and C compiler.
The following are always available unless undefined (or
-N was specified twice):
__FILE__ The input (or #include) file being
compiled (as a quoted string).
__LINE__ The line number being compiled.
__DATE__ The date of compilation as "Mmm dd yy"
__TIME__ The time of compilation as "hh:mm:ss"
__STDC__ The constant 1.
Thus,
printf("Bug at line %s,", __LINE__);
printf(" source file %s", __FILE__);
printf(" compiled on %s", __DATE__);
DRAFT PROPOSED ANSI STANDARD CONSIDERATIONS:
When CPP is itself compiled, many features of the Draft
Proposed Standard that are incompatible with existing
Page 4
cpp C Pre-Processor
preprocessors may be disabled. See the comments in
CPP's source for details.
Comments are removed from the input text. The comment
is replaced by a single space character. The -C option
preserves comments, writing them to the output file.
The '$' character is considered to be a letter. This is
a permitted extension.
The following new features of C are processed by CPP:
#elif expression (#else #if)
'\xNNN' (Hexadecimal constant)
'\a' (Ascii BELL)
'\v' (Ascii Vertical Tab)
#if defined NAME 1 if defined, 0 if not
#if defined (NAME) 1 if defined, 0 if not
#if sizeof (basic type)
unary +
123U, 123LU Unsigned ints and longs.
12.3L Long double numbers
token#token Token concatenation
#include token Expands to filename
#error tokens Flags an error
The Draft Proposed Standard has extended C, adding a
constant string concatenation operator, where
"foo" "bar"
is regarded as the single string "foobar". (This does
not affect CPP's processing but does permit a limited
form of macro argument substitution into strings as will
be discussed.)
The Standard Committee plans to add token concatenation
to #define command lines as follows:
The sequence "Token1 ## Token2" is treated
as if the programmer wrote "Token1Token2". This could
be used as follows:
#line 123
#define ATLINE foo ## __LINE__
ATLINE would be defined as foo123.
Page 5
cpp C Pre-Processor
If the tokens T1 and T2 are concatenated into T3, this
implementation operates as follows:
1. Expand T1 if it is a macro.
2. Expand T2 if it is a macro.
3. Join the tokens, forming T3.
4. Expand T3 if it is a macro.
If a macro parameter is immediately proceeded by a #, string
quotes (") are placed around the substituted parameter and
a \ character is inserted before each " or \ character that
appears surrounding,or inside a string literal or character
constant in the argument.
Example:
#define vprint(name, size) \
printf(#name "[" "size" "] = {\n")
... vprint(vector, VECSIZE);
expands (effectively) to
vprint("vector[123] = {\n");
Note that this will be useful if your C compiler
supports the new string concatenation operation noted
above.
EXTENSIONS
An extended macro facility is provided which allows and
arbitrary unix process to act as a macro expander. To
define a macro do one of the following:
#pragma defmacro name <file> options
#pragma defmacro name "file" options
This provides a mapping between macro names and the file
to be executed, which is on the include search path.
"options" is zero or more of the following:
recursive - when present, the macro is recursively expanded
delim=? - the default delimiter of ; is replaced with ?
other - other options are passed as arguments to the
macro expander
When a "defmacro" style macro's name is found, the name
and everything until the delimiter (includling all
matching {} [] () <> "" '' and comments found along the
way) is piped into the macro procedure's standard-input.
The procedure's standard output is scanned by CPP for
further processing. The expansion replaces the macro
call.
ERROR MESSAGES:
Many. CPP prints warning or error messages if you try
to use multiple-byte character constants
(non-transportable) if you #undef a symbol that was not
defined, or if your program has potentially nested
comments.
AUTHORS:
Martin Minow (Origional version)
LaMott Oren (Macro extensions and ANSI compatability)
BUGS:
The #if expression processor uses signed integers only.
I.e, #if 0xFFFFu < 0 may be TRUE.
This program differs from tha ANSI specification as follows:
Trigraph sequences aren't implemented.