Skip to main content
Ctrl+K
Black Magic  documentation - Home Black Magic  documentation - Home
  • F.A.Q.
  • C Compilation
  • Preprocessor
  • Getting started: using existing macros
  • A log library
  • Optional arguments: simple case
  • Optional arguments: General case
  • Counting arguments
  • Quotes about macros
  • Reference
    • Macros for writing macros
    • Terminal colors
    • Logging Library
    • Enum utilities
    • White magic
  • .rst

Black Magic

Black Magic#

impossible is not a C keyword

Learn about C preprocessor tricks

This book delves into techniques to generate C code with the preprocessor, starting with a reminder about what the preprocessor is and how it is integrated in the C compilation pipeline, then building up increasingly complex tools anyone can use in their C projects.

  • F.A.Q.
  • C Compilation
    • Phases of translation
    • Tokenizing
  • Preprocessor
    • Directives
    • The operators
  • Getting started: using existing macros
    • Constants
    • Debugging constants
    • Function-like
  • A log library
    • Objective
    • Split string literals
    • Current file name
    • Current function and line
    • Define a simple macro
    • Define a variadic macro
    • Bonus feature: Log an expression and its result
    • Convert the line number to a string literal
    • Configurable log level
    • Recap
  • Optional arguments: simple case
    • Single optional argument
  • Optional arguments: General case
    • Objective
  • Counting arguments
    • Objective
    • Solution
    • Usage example
  • Quotes about macros
  • Reference
    • Macros for writing macros
    • Terminal colors
    • Logging Library
    • Enum utilities
    • White magic

next

F.A.Q.

By Antoine Gagniere

© Copyright 2023-2024.