[Solved] Preprocessor examples in C language


The biggest example would be

 #include<stdio.h>

But there are a fair amount. You can also define macros:

 #define MAX(X,Y) (((X) > (Y)) ? (X) : (Y))

And use header guards

#ifndef A_H
#define A_H

// code

#endif

There are proprietary extensions that compilers define to let you give processing directives:

#ifdef WIN32 // WIN32 is defined by all Windows 32 compilers, but not by others.
#include <windows.h>
#else
#include <unistd.h>
#endif

And the if statement cause also be used for commenting:

#if 0

int notrealcode = 0;

#endif

I often use the preprocessor to make debug builds:

#ifdef EBUG
printf("Debug Info");
#endif

$ gcc -DEBUG file.c //debug build
$ gcc file.c //normal build

And as everyone else has pointed out there are a lot of places to get more information:

9

solved Preprocessor examples in C language