# This Developer Extended the C Preprocessor with Built-in Debugging and Mapping

Original title: Fun Extending the C Preprocessor

> Hacker News story 50106792 · language: en · submitted 2026-10-15
> Web version: https://zeli.app/story/50106792
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 55 · by [david2ndaccount](<https://news.ycombinator.com/user?id=david2ndaccount>) · 💬 39
[original](<https://www.davidpriver.com/Fun-Extending-the-C-Preprocessor.html>) · [HN discussion](<https://news.ycombinator.com/item?id=50106792>)

## Summary

While building his own C2Y compiler, David Priver added extensions to the C preprocessor that remove the need for unreadable macro tricks. __print() and __where() simplify debugging, __map() applies a macro across arguments without faking recursion, and __VA_COUNT__ gives the variadic argument count directly. The result is a more powerful, readable preprocessor that keeps the dark magic out of everyday code.

## Key quote

> The C Preprocessor is a powerful tool, but requires some unreadable dark magic to really take advantage of it. This isn't inherent to what you want to do with it though - it is merely a consequence of its underdeveloped machinery.

## HN discussion (39 comments)

### [raible](<https://news.ycombinator.com/item?id=50145698>)

> I use something like this to turn __VA_ARGS__ into count/pointer:
>
> // Create a stack-allocated argv from N args gcc, clang, tcc, mingw, msvc, etc
>
> // argc is always correct, for portability argv has a dummy element when argc==0
>
> // This avoids problematic 0-length compound literal arrays.
>
> \#define _ARG_CV(type, ...)  _ARG_CV1(((type []){0, __VA_ARGS__}))
>
> \#define _ARG_CV1(array)     _ALEN(array) - 1, array + (_ALEN(array) > 1)
>
> \#define _ALEN(array)         sizeof array / sizeof *array
>
> Then it's just:
>
> \#define sum(...) sum(_ARG_CV(int, __VA_ARGS__))

### [fuhsnn](<https://news.ycombinator.com/item?id=50144075>)

> There was a "__VA_TAIL__" WG14 proposal[1] that made it pretty simple to build custom map-like expansions, the OP's map example would be like:
>
> \> #define T(x, ...) printf(#x " = %d\n", x); __VA_TAIL__()
>
> \> T(1, 2, 3, 4, x, y, z)
>
> You can play with it in the proposal author's ellipsis[2] and my slimcc[3], it's simple enough to implement (only about 30 lines of C) so I kept it in despite not seeing signs of it getting accepted.
>
> [1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3307.htm
>
> [2] https://codeberg.org/gustedt/ellipsis
>
> [3] https://github.com/fuhsnn/slimcc

### [teo_zero](<https://news.ycombinator.com/item?id=50138651>)

> There are a couple of constructs that you end up re-creating as soon as you need non-trivial preprocessing.
>
> One of those is the two-stage CAT, another one is the NARG the article talks about.
>
> __COUNTER__ is going to be added to C29, the next version of the standard, maybe there's hope for __VA_COUNT__ and __CAT__ too!

### [andai](<https://news.ycombinator.com/item?id=50142987>)

> It's always bothered me that programming languages aren't programmable.
>
> Well, I keep hearing that Lisp is, but I haven't put much effort into it. (I'd need a Lisp that runs in the browser, for starters!) Maybe I should take another look...
>
> Or maybe I wish the VM was programmable. "Warn me when this type of operation takes place", or "Print the name of every function before it is invoked", etc. I end up just copy-pasting my own temporary statements all over the program.

### [HexDecOctBin](<https://news.ycombinator.com/item?id=50139148>)

> Has anyone tried to extend the C Preprocessor to be a fully turing complete language (perhaps something like Snobol) to allow for Terra like meta-programming?
>
> (I am not talking about metalang99 or Cello like stuff, which exploits the Turing tarpit of the currently specified preprocessor but rather tasteful additions to the preprocessor itself).

---

## Cite

- Page: https://zeli.app/story/50106792
- Date: 2026-10-15
- Source: davidpriver.com (https://www.davidpriver.com/Fun-Extending-the-C-Preprocessor.html)
- Hacker News: https://news.ycombinator.com/item?id=50106792

## Other languages

- zh: https://zeli.app/zh/story/50106792 · markdown: https://zeli.app/zh/story/50106792.md
- ja: https://zeli.app/ja/story/50106792 · markdown: https://zeli.app/ja/story/50106792.md
- ko: https://zeli.app/ko/story/50106792 · markdown: https://zeli.app/ko/story/50106792.md
- de: https://zeli.app/de/story/50106792 · markdown: https://zeli.app/de/story/50106792.md
- es: https://zeli.app/es/story/50106792 · markdown: https://zeli.app/es/story/50106792.md
- ru: https://zeli.app/ru/story/50106792 · markdown: https://zeli.app/ru/story/50106792.md
