#include "filename" searches current directory and
system-dependent directories (on Unix, the system-dependent directory is
/usr/include)
#include <filename> searches only
system-dependent directories (not the current directory)
filename can be a relative path (like
#include <subdir/file.h>)
filename can also be an absolute path (like
#include </home/chicken/egg.h>, but this is non-portable
and therefore not recommended
#include "filename" form)
/usr/include)
#included files can include other files (which can include
other files...)
#define name defines an empty macro in the
preprocessor
#define DEBUG
#define SILLY
#define name token(s) defines a macro
which, when used later in the code, is replaced the symbol(s) in the token list
#define PI 3.141593, a statement like
PI + PI would be replaced by the preprocessor with
3.141593 + 3.141593
PIE - PI
would be replaced with PIE - 3.141593
#define name(args) token(s)
#define SQUARE(x) ((x) * (x)) defines a macro which
replaces SQUARE(value) with ((value) * (value))
#define SQUARE(x) x * x,
something like 4 / SQUARE(2) would get expanded to
4 / 2 * 2 which would be evaluated from left to right as
"4 / 2 * 2" ->
"2 * 2" ->
"4"
instead of the intended
"4 / (2 * 2)" ->
"4 / 4" ->
"1"
#define PI 3.141593 #define PI2 PI * 2 #define SQR(z) ((z) * (z)) #define PI2SQ SQR(PI2)
12 * PI2SQ is expanded as follows:
PI2SQ and expands the
statement to 12 * SQR(PI2)
SQR, leaving 12 * ((PI2) * (PI2))
PI2, leaving 12 * ((PI * 2) * (PI * 2))
PI references,
leaving 12 * ((3.141593 * 2) * (3.141593 * 2))
\ as the
last character on a line
#define SPLIT_EXPR ((12.3456789 * 9.87654) + \ (54321 - 12345)) #define NOT_LESS_THAN(a, b) \ if ((a) > (b)) \ (a) = (b)
#define TEMPORARY(a, b) (((a) * (b)) / 12345.678) val = TEMPORARY(exp, sect); #undef TEMPORARY
__DATE__ - string containing current date (like "Jan 1 2000")
__TIME__ - string containing current time (like "12:34:56)
__FILE__ - string containing source file name (like "file.c")
__LINE__ - current line number in source file,
expressed as an integer (like 7)
__STDC__ - non-zero integer in an ANSI C preprocessor,
implementation-defined elsewhere (could be set to 0, could be undefined)
#ifdef name - if name has been defined
as a preprocessor macro, process the following code
#ifndef name - if name has
not been defined, process the following code
#endif - turn off the previous conditional directive
#else - reverse the meaning of the previous conditional
directive
#ifdef __STDC_ #define CC_TYPE "standard C" #else #define CC_TYPE "nonstandard C" #endif
defined(name) - evaluates to 1 if name has
been defined
#if defined(DEBUG) is the same as #ifdef DEBUG
#if expression - if expression evaluates
to a non-zero value, process the following code
#if 0 code which should not be compiled #endifor as complicated as:
#if defined(UNIX) || \ (defined(MYSYS) && \ (defined(SYS_VERSION) && ( (SYS_VERSION > 17.2))) special code #endif
#elif expression - ANSI C addition which allows:
#ifdef expression-1 blah blah blah #else # if expression-2 blech blech blech # endif #endifto be written as:
#ifdef expression-1 blah blah blah #elif expression-2 blech blech blech #endif
#pragma was first proposed in ANSI, the GNU C
compiler implementer (who didn't like #pragma took
"implementation-defined" to heart. If a #pragma was encountered
by GCC, the compiler would
/usr/games/hack (a Unix game)
/usr/games/rogue (another Unix game)
"You are in a maze of twisty compiler
features, all different