
C preprocessor tricks, tips, and idioms (2015) - Pete_D
https://github.com/pfultz2/Cloak/wiki/C-Preprocessor-tricks,-tips,-and-idioms
======
WalterBright
I used to use all sorts of preprocessor tricks in my C code. I eventually made
an effort to eliminated all preprocessor use in the code (except for #include,
where there was no alternative).

The result was surprisingly pleasing. The code looked much nicer without all
the #'s breaking up the indentation, and it made C look like a more modern
language :-)

------
sigjuice
There are lots of horrific weapons like this to ever torment the universe.
e.g.
[http://p99.gforge.inria.fr/p99-html/index.html](http://p99.gforge.inria.fr/p99-html/index.html)

~~~
coldpie
I work in C all day every day. It's fine, I get by. And then I run into
macros. Fucking macros.

Hey guess what REQUEST and REQUEST_FIXED_SIZE do here:
[https://gitlab.freedesktop.org/xorg/xserver/blob/master/dix/...](https://gitlab.freedesktop.org/xorg/xserver/blob/master/dix/extension.c#L223)
Did you guess "declares a new variable called 'stuff'" and "returns early",
respectively?

Do you think dixAllocateObjectWithPrivates is a function here?
[https://gitlab.freedesktop.org/xorg/xserver/blob/master/dix/...](https://gitlab.freedesktop.org/xorg/xserver/blob/master/dix/property.c#L274)
Haha, think again! Macro.

Guess what fbGetPixmapBitsData does here:
[https://gitlab.freedesktop.org/xorg/xserver/blob/master/fb/f...](https://gitlab.freedesktop.org/xorg/xserver/blob/master/fb/fbpict.c#L291)
Did you guess assign values to the latter 3 arguments, two of which aren't
even passed by reference??

I'm picking on the xserver because it's my most memorable encounter with bad
macros, but agh. Agh!

~~~
taylodl
Where do you work that you get to work in C all day every day? I haven’t been
able to do that in over 25 years. Sometimes I miss those days. Then you see
one of these stupid macros!

~~~
waiseristy
Come to automotive, you can program in c90 all the live long day

