Monday, November 28, 2011

C compiler preprocessors

C compiler preprocessors:-Preprocessor commands are executed before the compiler compiles the source code.
#include preprocessor directive
• causes a copy of a specified file to be
included in place of the directive
• Two versions:
– #include “filename”
preprocessor searches in the same directory as
the file being compiled for the file to be
included
– #include <filename>
used for standard library header files, the
search normally performed through predesignated
directories
2
7
#define preprocessor directive
• creates symbolic constants and
macros.
ex- #define PI 3.14159
identifier replacement-text
replaces all subsequent occurrences of the
symbolic constant PI with the numeric
constant 3.14159.

#include :-insert a source file.
#define :-Define a preprocessor constant.
#if :-Branch based on an expression.
#ifdef :-Branch if preprocessor constant has been defined?
#ifndef :-Branch is a preprocessor constant has NOT been defined.
#line :-Specify the number of the next source line.
#undef :-Remove a preprocessor constant.
#pragma:-Perform an implementation dependent action???
#else :-Executed if #if #ifdef or #ifndef fails.
#error :-Write an error message.
#elif :-Executed when an #if fails.
#endif :-Close #if #ifdef or #ifndef

No comments:

Post a Comment