Created
October 28, 2013 17:09
-
-
Save psobko/7200704 to your computer and use it in GitHub Desktop.
Preprocessor Macros
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://www.tutorialspoint.com/cprogramming/c_preprocessors.htm | |
#define Substitutes a preprocessor macro | |
#include Inserts a particular header from another file | |
#undef Undefines a preprocessor macro | |
#ifdef Returns true if this macro is defined | |
#ifndef Returns true if this macro is not defined | |
#if Tests if a compile time condition is true | |
#else The alternative for #if | |
#elif #else an #if in one statement | |
#endif Ends preprocessor conditional | |
#error Prints error message on stderr | |
#pragma Issues special commands to the compiler, using a standardized method | |
--- | |
#define MAX_ARRAY_LENGTH 20 | |
#undef FILE_SIZE | |
#define FILE_SIZE 42 | |
#ifndef MESSAGE | |
#define MESSAGE "You wish!" | |
#endif | |
#ifdef DEBUG | |
/* Your debugging statements here */ | |
#endif | |
//Continuation (multiple lines) | |
#define message_for(a, b) \ | |
printf(#a " and " #b ": We love you!\n") | |
//Parametrized Macros | |
#define square(x) ((x) * (x)) | |
#define MAX(x,y) ((x) > (y) ? (x) : (y)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment