|
|
The preprocessing operators are evaluated left to right, without any defined precedence.
#define identifier token-sequence[opt]where identifier will be replaced with token-sequence wherever identifier appears in regular text.
#define identifier( identifier-list[opt] ) token-sequence[opt]where the macro parameters are contained in the comma-separated identifier-list. The token-sequence following the identifier list determines the behavior of the macro, and is referred to as the replacement list. There can be no space between the identifier and the ( character. For example:
#define FLM(a,b) a+bThe replacement-list a+b determines that the two parameters a and b will be added.
#define identifier( identifier-list[opt], ... ) token-sequence[opt]where if the identifier-list is not present, there is also no comma. This form of macro definition accepts zero or more arguments matching the ellipsis. Those arguments, if any, that match the ellipsis in an invocation of this macro replace the special identifier __VA_ARGS__ optionally present in the replacement token sequence.
FLM(3,2)
Assume that M1 is defined as 3:
#define M1 3When the function-like macro FLM is used, use of the # or ## operators will affect expansion (and the result), as follows:
Definition | Invocation | Result | Expansion? |
a+b | FLM(M1,2) | 3+2 | Yes, Yes |
#a | FLM(M1,2) | "M1" | No |
a##b | FLM(M1,2) | M12 | No, No |
a+#a | FLM(M1,2) | 3+"M1" | Yes, No |
In the last example line, the first a in a+#a is expanded, but the second a is not expanded because it is an operand of the # operator.
#undef identifierThere is no effect if the definition doesn't exist.
#include "filename"causes the entire line to be replaced with the contents of filename. The following directories are searched, in order.
#include <filename>causes the entire line to be replaced with contents of filename. The angle brackets surrounding filename indicate that filename is not searched for in the current directory.
#include preprocessing-tokensThe preprocessing tokens are processed the same way as when they are used in normal text. Any defined macro name is replaced with its replace-
Different segments of a program may be compiled conditionally. Conditional compilation statements must observe the following sequence:
Is true if integral-constant-expression evaluates to nonzero.
If true, tokens following the if line are included.
The integral-constant-expression following the if is evaluated by following this sequence of steps:
The following table shows how various types of constant expressions following a #if would be evaluated. Assume that name is not defined.
Constant expression | Step 1 | Step 2 | Step 3 |
---|---|---|---|
__STDC__ | 1 | 1 | 1 |
!defined(__STDC__) | !1 | !1 | 0 |
3||name | 3||name | 3||0 | 1 |
2 + name | 2 + name | 2 + 0 | 2 |
Is true if identifier is currently defined by #define or by the -D option to the cc command line.
Is true if identifier is not currently defined by #define (or has been undefined).
Indicates alternate if-condition when all preceding if-conditions are false.
Indicates alternate action when no preceding if or elif conditions are true. A comment may follow the else, but a token may not.
Terminates the current conditional. A comment may follow the endif, but a token may not.
#line constant "filename"causes the compiler to believe, for the purposes of error diagnostics and debugging, that the line number of the next source line is equal to constant (which must be a decimal integer) and the current input file is filename (enclosed in double quotes). The quoted file name is optional. constant must be a decimal integer in the range 1 to MAXINT. MAXINT is defined in limits.h.
#assert predicate (token-sequence)associates the token-sequence with the predicate in the assertion name space (separate from the space used for macro definitions). The predicate must be an identifier token.
#assert predicateasserts that predicate exists, but does not associate any token sequence with it.
The compiler provides the following predefined predicates by default on the 3B2:
#assert machine ( u3b2 ) #assert system ( unix ) #assert cpu ( M32 )The following defaults apply to the Intel386 microprocessor:
#assert machine ( i386 ) #assert system ( unix ) #assert cpu ( i386 )
Any assertion may be removed by using #unassert, which uses the same syntax as assert. Using #unassert with no argument deletes all assertions on the predicate; specifying an assertion deletes only that assertion.
An assertion may be tested in a #if statement with the following syntax:
#if #predicate(non-empty token-list)For example, the predefined predicate system can be tested with the following line:
#if #system(unix)which will evaluate true.
The #ident directive is used to help administer version control information.
#ident "version"puts an arbitrary string in the .comment section of the object file. The .comment section is not loaded into memory when the program is executed.
#pragma pp-tokensspecify implementation-defined actions.
which is identical in function to #ident "version".
which identifies identifier as a weak global symbol,
or
#pragma weak identifier = identifier2
which identifies identifier as a weak global symbol whose value is the same as identifier2. identifier should otherwise be undefined. See ``Handling multiply defined symbols'' in ``C and C++ compilation system'' for more information on weak global symbols.
which identifies identifier as a function whose type was int in previous releases of the compilation system, but whose type is unsigned int in this release. The declaration for identifier must precede the #pragma.
unsigned int strlen(const char*); #pragma int_to_unsigned strlen#pragma int_to_unsigned makes it possible for the compiler to identify expressions in which the function's changed type may affect the evaluation of the expression. In the -Xt mode the compiler treats the function as if it were declared to return int rather than unsigned int.
which controls the layout of structure offsets.
n is a number,
1, 2, or 4, that specifies the strictest alignment
desired for any structure member.
If n is omitted,
the alignment reverts to the default,
which may have been set by the
-Zp
option to
cc.
A value of 4 is the default.
A preprocessing line consisting of
#error token-sequencecauses the compiler to produce a diagnostic message containing the token-sequence, and stop.
The following identifiers are predefined as object-like macros:
With the exception of __STDC__, these predefined names may not be undefined or redefined. Under compilation mode -Xt, __STDC__ may be undefined (#undef __STDC__) to cause a source file to think it is being compiled by a previous version of the compiler.