972
edits
[unchecked revision] | [unchecked revision] |
m (Bot: Replace deprecated source tag with syntaxhighlight) |
m (Bot: Replace deprecated source tag with syntaxhighlight) |
||
Line 9:
The most familiar use of the preprocessor is to include header files (containing function declarations, definition of constants etc.):
<
#include <stdio.h>
#include "myheader.h"
</syntaxhighlight>
The effect is that the contents of the given header file are pasted into the source file. The ''technical'' difference between <> and "" is that the compiler is allowed to satisfy <> includes internally, i.e. without actually accessing any on-disk files of that name. None of the prominent compilers do this, to the knowledge of the author, but it has become common practice to use <> for system headers and "" for your own header files.
Line 134:
Assertions are used to catch situations which should never happen, even under error circumstances. If the condition given in the parantheses does not evaluate to "true", a diagnosis is printed which contains source file name, line number, and (since C99) name of the current function; the program then calls abort().
<
#include <assert.h>
Line 140:
assert( 1 != 2 );
assert( gdt_ptr != null );
</syntaxhighlight>
For production code, assertions may be turned off by defining NDEBUG:
Line 150:
Note that <assert.h> does not have (or need) a header guard, i.e. can be included multiple times in a source file, and that whether NDEBUG is defined or not is evaluated anew ''at every inclusion of <assert.h>''. You can thus enable / disable assertions at a very fine-grained level if necessary:
<
#include <assert.h>
Line 171:
#include <assert.h>
#endif
</syntaxhighlight>
== See also ==
|