Tuesday, June 2, 2009

Directives and Preprocessor.....................

Directive

The instructions to the preprocessor appear in the source as directives and
can be easily spotted in the source code because they all begin with a hash (#) character,
appearing as the first non blank character on a line. The hash character usually appears
on column 1 and is immediately followed by the directive keyword

Example
    #define
    #include
    #ifndef

Preprocessor

The preprocessor reads the source code and responds to directives
embedded in it to produce a modified version of the source, which is fed to the
compiler. The preprocessor is still an important part of C, C++,

Macro

The macro has a name that,when found elsewhere in the text, is replaced with the string of characters defined as the value of the macro. It is possible to specify parameters that are to be used as part of the macro expansion.

Example

#define min(a,b) ((a) < (b) ? (a) : (b))















































































Directive
Description

#define


Defines a name as a macro that the preprocessor will expand

#elif


Provides an alternative expression to be evaluated by an #if directive.

#else


Provides an alternative set of code to be compiled if an #if, #ifdef,

or #ifndef is false.

#error


Produces an error message and halts the preprocessor.

#if


Compiles the code between this directive and its matching #endif only

if evaluating an arithmetic expression results in a nonzero value.


#ifdef


Compiles the code between this directive and its matching #endif only

if the named macro has been defined.

#ifndef


Compiles the code between this directive and its matching #endif only

if the named macro has not been defined.

#include


Searches through a list of directories until it finds the named

file; then it inserts the contents of the file just as if it had

been inserted by a text editor.


#include_Next



The same as #include, but this directive begins the search for the file

in the directory following the one in which the current file was found.


#line



Specifies the line number, and possibly the file name, that is reported

to the compiler to be used to create debugging information in the object

file.


#pragma



A standard method of providing additional information that may be

specific to one compiler or one platform.


#undef



Removes a definition previously created by a #define directive.


#warning



Produces a warning message from the preprocessor.


##



The concatenation operator, which can be used inside a macro to combine

two strings into one.

No comments:

Post a Comment

Search Ranjeet's Blog