The #define directive takes two forms: defining a constant and creating a macro.

Defining a constant

#define token [value]
When defining a constant, you may optionally elect not to provide a value for that constant. In this case, the token will be replaced with blank text, but will be "defined" for the purposes of #ifdef and ifndef. If a value is provided, the given token will be replaced literally with the remainder of the text on the line. You should be careful when using #define in this way; see this article on the c preprocessor for a list of gotchas.

Defining a parameterized macro

#define token(<arg> [, <arg>s ... ]) statement
For instance, here is a standard way of writing a macro to return the max of two values.
#define MAX(a, b) ((a) > (b) ? (a) : (b))
Note that when writing macros there are a lot of small gotchas; you can read more about it here: the c preprocessor . To define a multiline macro, each line before the last should end with a \, which will result in a line continuation.


C preprocessor tutorial