DEV Community

Lam
Lam

Posted on

1 1

Quick C Preprocessor Cheat Sheet

[Reference] file and line

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

[Reference] Stringification

#define STR(name) #name
char * a = STR(object);   #=> char * a = "object";
Enter fullscreen mode Exit fullscreen mode

[Reference] Token concat

#define DST(name) name##_s name##_t
DST(object);   #=> object_s object_t;
Enter fullscreen mode Exit fullscreen mode

[Reference] Macro

#define DEG(x) ((x) * 57.29)
Enter fullscreen mode Exit fullscreen mode

[Reference] Error

#if VERSION == 2.0
  #error Unsupported
  #warning Not really supported
#endif
Enter fullscreen mode Exit fullscreen mode

[Reference] If

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

[Reference] Defines

#define FOO
#define FOO "hello"

#undef FOO
Enter fullscreen mode Exit fullscreen mode

[Reference] Includes

#include "file"
Enter fullscreen mode Exit fullscreen mode

[Reference] Compiling

$ cpp -P file > outfile
Enter fullscreen mode Exit fullscreen mode

Reference

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay