The C preprocessor is the macro preprocessor for the C, Objective-C, and C++ computer programming languages. The preprocessor provides the ability for the inclusion of header files, macro expansions, conditional compilation, and line control. C Preprocessor Cheat Sheet is quick reference for the C macro preprocessor, which can be used independently of C/C++.
File and line
#define LOG(msg) console.log(__FILE__, __LINE__, msg)
#=> console.log("file.txt", 3, "hey")
Stringification
#define STR(name) #name
char * a = STR(object); #=> char * a = "object";
Token concat
#define DST(name) name##_s name##_t
DST(object); #=> object_s object_t;
Macro
#define DEG(x) ((x) * 57.29)
Error
#if VERSION == 2.0
#error Unsupported
#warning Not really supported
#endif
[Reference] If
#ifdef DEBUG
console.log('hi');
#elif defined VERBOSE
...
#else
...
#endif
Defines
#define FOO
#define FOO "hello"
#undef FOO
Includes
#include "file"
Compiling
$ cpp -P file > outfile
Top comments (0)