1
0
mirror of https://github.com/onkelbeh/cheatsheets.git synced 2025-10-16 15:38:44 +02:00
cheatsheets/c_preprocessor.md
Rico Sta. Cruz 511de900ba
Formatting updates (#2133)
- Update some sheets which have very long sections
- Remove `layout: 2017/sheet` (everything has the same layout now)
- Remove outdated sheets
2024-04-03 18:30:24 +11:00

952 B

title, category, intro
title category intro
C Preprocessor C-like Quick reference for the [C macro preprocessor](https://en.m.wikipedia.org/wiki/C_preprocessor), which can be used independent of C/C++.

Reference

{: .-three-column}

Compiling

$ cpp -P file > outfile

Includes

#include "file"

Defines

#define FOO
#define FOO "hello"

#undef FOO

If

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

Error

#if VERSION == 2.0
  #error Unsupported
  #warning Not really supported
#endif

Macro

#define DEG(x) ((x) * 57.29)

Token concat

#define DST(name) name##_s name##_t
DST(object);   #=> object_s object_t;

Stringification

#define STR(name) #name
char * a = STR(object);   #=> char * a = "object";

file and line

#define LOG(msg) console.log(__FILE__, __LINE__, msg)
#=> console.log("file.txt", 3, "hey")