Online Reference
C Reference - Preprocessor directivesDirective SyntaxDirective DescriptionFile inclusion #include <filename.h>replace directive with file from C library path#include "filename.h"replace directive with file from source pathMacro definition #define name textreplace every occurrence of name with text#define name(args) textreplace every occurrence of name with argument with text#undef namesuspends macro substitutionConditional compilation #if expressionif expression is true compile section#ifdef name#if defined(name)if name is defined compile section#ifndef name#if !defined(name)if name is not defined compile section#elifelse if expression is true compile section#elseelse compile section#endifterminates #if block\ continue definition in next line##parameters concatenationOther directives #pragma tokendo compiler dependent action#error tokenwrite diagnostic message/* text */comment// textline comment (C++ feature - not ANSI C) #includeSyntax:#include <filename.h>#include "filename.h"Description:Include header file instead of directive.Example:#include <stdio.h>#include "my_defs.h" int main(){ printf("Example");} #defineSyntax:#define name text#define name(args) textDescription:Replace every occurrence of name with textExample:#define DEBUG#define C 3.0e8#define abs(X) ((X)>0 ? (X) : -(X) #undefSyntax:#undef nameDescription:Suspends macro substitution of nameExample:#undef C#undef abs #ifSyntax:#if nameDescription:If expression is true compile sectionExample:#define DEBUG 1#if DEBUG : code will be compiled when DEBUG is 1 :#endif #ifdefSyntax:#ifdef nameDescription:If name is defined compile sectionExample:#define DEBUG#ifdef DEBUG : code will be compiled when DEBUG is defined :#endif #ifndefSyntax:#ifndef nameDescription:If name is not defined compile sectionExample:#define VER2#ifndef VER2 : code will be compiled when VER2 is not defined :#endif #elifSyntax:#if name :#elif name :#endifDescription:Else if expression is true compile sectionExample:#define VER1 0#define VER2 1#if VER1 : //code will not be compiled#elif VER2 : //code will be compiled#endif #elseSyntax:#if name :#else :#endifDescription:Else compile sectionExample:#define VER 0#if VER : //code will not be compiled#else : //code will be compiled#endif #endifSyntax:#if name :#elseif name :#else :#endifDescription:Terminates #if blockExample:#if VER :#endif \Syntax:#define name text \ text \ textDescription:Continue definition in next lineExample:#define X { {1,2}, \ {2,4}, \ {3,6} } ##Syntax:#define name text(arg) arg##textDescription:Continue definition in next lineExample:#define con(X,Y) X##Y /* */Syntax:/* text */Description:Text commentExample:/* This is a comment*/ /* and also this is a comment */ //Syntax:// textDescription:Line comment (non ANSI C - C++ feature)Example:// This is a comment// and also this is a comment
#include <filename.h>
#include "filename.h"
#define name text
#define name(args) text
#undef name
#if expression
#ifdef name
#if defined(name)
#ifndef name
#if !defined(name)
#elif
#else
#endif
\
##
#pragma token
#error token
/* text */
// text
#include <stdio.h>
#include "my_defs.h"
int main()
{
printf("Example");
}
#define DEBUG
#define C 3.0e8
#define abs(X) ((X)>0 ? (X) : -(X)
#undef C
#undef abs
#if name
#define DEBUG 1
#if DEBUG
:
code will be compiled when
DEBUG is 1
#ifdef DEBUG
DEBUG is defined
#define VER2
#ifndef VER2
VER2 is not defined
#elif name
#define VER1 0
#define VER2 1
#if VER1
: //code will not be compiled
#elif VER2
: //code will be compiled
#define VER 0
#if VER
#elseif name
#define name text \
text \
text
#define X { {1,2}, \
{2,4}, \
{3,6} }
#define name text(arg) arg##text
#define con(X,Y) X##Y
/*
This is
a comment
*/
/* and also this is a comment */
// This is a comment
// and also this is a comment
© 2006-2008 RapidTables.com