> Online tutorial : Directive in c
Showing posts with label Directive in c. Show all posts
Showing posts with label Directive in c. Show all posts

Directive in c

Directive in c

ifndef in c example

#ifndef, Conditional compilation directives
Syntax:
#if
#else
#endif

#if
#elif
#endif

1.The compiler only compiles the lines that follow the #if directive when evaluates to non-zero.
2.Otherwise, the compiler skips the lines that follow until it encounters the matching #else or #endif.
3.If the expression evaluates to false and there is a matching #else, the lines between the #else and the #endif are compiled.
4.#if directives can be nested, but matching #else and #endif directives must be in the same file as the #if.
5.#elif is like #else except the else block is only compiled if the expression after #elif is non-zero.

#ifndef
evaluates to 1 if the symbol specified by has not been defined.
Example




#ifndef Quiet
PrintDiagnostics();
#endif

ifdef in c

#ifdef, Conditional compilation directives

Syntax:

#if
#else
#endif

#if
#elif
#endif


1)The compiler only compiles the lines that follow the #if directive when evaluates to non-zero.
2)Otherwise, the compiler skips the lines that follow until it encounters the matching #else or #endif.
3)If the expression evaluates to false and there is a matching #else, the lines between the #else and the #endif are compiled.
4)#if directives can be nested, but matching #else and #endif directives must be in the same file as the #if.
5)#elif is like #else except the else block is only compiled if the expression after #elif is non-zero.


#ifdef  evaluates to 1 if the symbol specified by has been previously
defined with a #define directive.


Example

#ifdef DEBUG
printf("Total space %d\n", space);
#endif

if directives

#if directive 
Conditional compilation directives
Syntax:
#if
#else
#endif

1)The compiler only compiles the lines that follow the #if directive when
evaluates to non-zero.
2)Otherwise, the compiler skips the lines that follow until it encounters the
matching #else or #endif.
3)If the expression evaluates to false and there is a matching #else, the
lines between the #else and the #endif are compiled.
4)#if directives can be nested, but matching #else and #endif directives must
be in the same file as the #if.

Example

#if defined(NEARPOINTERS)
space = farcoreleft();
#elif defined(FARPOINTERS)
space = coreleft();
#else
#error Unsupported memory model
#endif

#error in c

#error (directive)
Issues error message
Syntax:
#error

If this line of code is compiled by the compiler, a fatal error message will be issued for this line and include the text defined by .
Example:

#if !defined(MODEL)
#error Building model not defined
#endif