C++ Preprocessor

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

If

#ifdef DEBUG
  console.log('hi');
#elif defined VERBOSE
  ...
#else
  ...
#endif

Defines

#define FOO
#define FOO "hello"
#undef FOO

Includes

#include "iostream"
#include <iostream>
Comments