All About Header Files |
C C C |
|
13C |
|
C C C |
|
C C |
The rest of this chapter describes the standard C header files. Header files specific to particular C compilers are not included in the discussion. To learn about compilerspecific header files, refer to your compiler’s documentation and look at the files themselves.
Your compiler may not contain all the header files described in this chapter. If that is the case, the contents of the header file (or files) are probably included in another header file. A likely choice is the stdlib.h file, which often serves as a catchall.
The assert.h File (ANSI)
The assert.h header file is used for the assert() macro. Note that assert() is always implemented as a macro and is never directly implemented as a function.
You can test a condition with the assert() macro. If the condition tests as TRUE, nothing happens. If the condition tests as FALSE, the following message is printed to
stderr:
Assertion failed: condition, filename, linenumber
The condition is printed as a text string, along with the source file name and the current line number in the current file. After the message is printed, the program calls abort() to end the program—a failed assert() definitely ends your program!
To turn off the effect of the assert() macro, you must define the NDEBUG identifier. When this identifier is defined, assert() evaluates as ((void)0), which is effectively nothing.
The typical definition of the assert() macro is
#define assert(exp)((exp) ? (void) 0 : \ _assert(#exp,_ _FILE_ _,_ _LINE_ _) )
If the expression evaluates to FALSE, the condition, filename and line number in the assert() macro are passed to a function. If the condition evaluates to TRUE, the macro evaluates to ((void)0).
The assert() macro is a valuable tool when you are debugging your program, but you must remember to define NDEBUG when creating the production version of the program.