{"id":24125756,"url":"https://github.com/agagniere/blackmagic","last_synced_at":"2025-09-18T17:31:05.773Z","repository":{"id":189478820,"uuid":"680608275","full_name":"agagniere/blackmagic","owner":"agagniere","description":"C preprocessor tricks, explained","archived":false,"fork":false,"pushed_at":"2025-07-29T11:41:15.000Z","size":227,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-29T13:54:59.507Z","etag":null,"topics":["c","preprocessor","tutorial","zig-package"],"latest_commit_sha":null,"homepage":"https://agagniere.github.io/blackmagic/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/agagniere.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-08-19T19:43:47.000Z","updated_at":"2025-07-29T11:41:20.000Z","dependencies_parsed_at":"2024-03-17T20:25:38.192Z","dependency_job_id":"83bf234d-3752-4c18-a7e5-8d3e171c141e","html_url":"https://github.com/agagniere/blackmagic","commit_stats":null,"previous_names":["agagniere/blackmagic"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/agagniere/blackmagic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agagniere%2Fblackmagic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agagniere%2Fblackmagic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agagniere%2Fblackmagic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agagniere%2Fblackmagic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/agagniere","download_url":"https://codeload.github.com/agagniere/blackmagic/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agagniere%2Fblackmagic/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275804590,"owners_count":25531711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-18T02:00:09.552Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","preprocessor","tutorial","zig-package"],"created_at":"2025-01-11T15:37:19.542Z","updated_at":"2025-09-18T17:31:05.768Z","avatar_url":"https://github.com/agagniere.png","language":"C","readme":"# Black Magic\n\n*`impossible` is not a C keyword*\n\n**Learn about C preprocessor tricks**\n\nThis book delves into techniques to generate C code with the preprocessor,\nstarting with a reminder about what the preprocessor is and how it is integrated in the C compilation pipeline,\nthen building up increasingly complex tools anyone can use in their C projects.\n\n[Read it online !](https://agagniere.github.io/blackmagic/)\n\n## Tools\nAdd this project as a dependency to your C project today (using Zig, Nix or Conan) to get:\n- ANSI color codes as a string literal by writing `COLOR(UNDERLINED, BOLD, RED)` [`blackmagic/color.h`](include/blackmagic/color.h)\n- Convert enums to/from strings [`blackmagic/enum.h`](include/blackmagic/enum.h)\n- Logs with a compile-time configurable format and level [`blackmagic/log.h`](include/blackmagic/log.h). Possible formats include:\n   - colored console\n   - JSON\n   - Markdown table\n   - custom callback\n\n## Roadmap\nI would like to explain the following tricks in the book:\n- [x] Logging\n- [ ] Default arguments\n- [ ] Function overloading\n- [ ] Enum to/from string\n- [ ] Serialization / Deserialization of a structure\n- [ ] Unit-tests library\n\n## Extras\n- Sphinx directive to show C code before and after preprocessing\n- Custom pygment lexer to color the code the way the preprocessor sees it\n\n## Use it\n\n### With Zig build as your C package manager\n\nAdd the dependency in your `build.zig.zon` by running the following command:\n```shell\nzig fetch --save git+https://github.com/agagniere/blackmagic#master\n```\n\nThen, in your `build.zig`:\n```zig\nconst blackmagic = b.dependency(\"blackmagic\", .{});\n// wherever needed:\nexe.addIncludePath(blackmagic.path(\"include\"));\n```\n\n### With Conan\n\nAdd the dependency in your `conanfile.txt`\n```toml\n[requires]\nblackmagic/0.3\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagagniere%2Fblackmagic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagagniere%2Fblackmagic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagagniere%2Fblackmagic/lists"}