Everything you want to know about C/C++ pre-processor but couldn't ask
summary
Claims the C/C++ preprocessor is almost Turing complete and demonstrates concrete tricks and pitfalls: string-literal concatenation that changes compiler input, a swap macro fixed by argument parenthesization and a generated temp name using token-pasting with a required double expansion to avoid swap macro name clash, a RAII-style resource macro using nested for-loops that works for FILE and va_list, and a full preprocessor FizzBuzz implemented with recursive-repeat, decrement and boolean hacks and validated via the #include-as-test technique — it compiles and the tests pass.
AI-written summary · about
chapters (8)
- 0:00Start
- 3:16String Literal Concatenation
- 5:56Swap Macro
- 6:08Swap Micro
- 26:11Fizzbuzz in the Preprocessor
- 28:07Repeat Macro
- 28:46How Do We Decrement a Variable
- 35:49Fizzbuzz
related talks
01h 06m“C++ Metaprogramming: Journey from simple to insanity and back"
06mCode Generation: The Lisp Way
45mC++ is a Metacompiler
57mIntroduction to C++ Template Metaprogramming
01h 00mconstexpr: Applications
01h 01m“How bad is Meta-Programming still today?"
01h 01mEasy to Use, Hard to Misuse: Declarative Style in C++
01h 01mExpressive Compile Time Parsers
