Menu

gitpiper

C Preprocessor Cheat Sheet in September 2024

Last Updated: 18 September 2024

README.md

{: .-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")

338+ more cheat sheets for you in September 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️