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.
Add this project as a dependency to your C project today (using Zig, Nix or Conan) to get:
- ANSI color codes as a string literal by writing
COLOR(UNDERLINED, BOLD, RED)blackmagic/color.h - Convert enums to/from strings
blackmagic/enum.h - Logs with a compile-time configurable format and level
blackmagic/log.h. Possible formats include:- colored console
- JSON
- Markdown table
- custom callback
I would like to explain the following tricks in the book:
- Logging
- Default arguments
- Function overloading
- Enum to/from string
- Serialization / Deserialization of a structure
- Unit-tests library
- Sphinx directive to show C code before and after preprocessing
- Custom pygment lexer to color the code the way the preprocessor sees it
Add the dependency in your build.zig.zon by running the following command:
zig fetch --save git+https://github.com/agagniere/blackmagic#masterThen, in your build.zig:
const blackmagic = b.dependency("blackmagic", .{});
// wherever needed:
exe.addIncludePath(blackmagic.path("include"));Add the dependency in your conanfile.txt
[requires]
blackmagic/0.3