Hacker News new | ask | show | jobs
by linkdd 768 days ago
This is the work of a wizard.

I've known C for almost 20 years, and never would I have thought the macro system was powerful enough to allow such black magic.

This is awesome!

4 comments

> I've known C for almost 20 years

The author is only 19 years old. I feel really dumb now.

You might also be interested in metalang99 by the same author.
Yeah xmacros (the style of macro use) are pretty fancy. "Classically" they are used for creating and accessing type safe generics or for reducing boilerplate for hardware register and interrupt definitions.

They are kind of cursed but at their core they are actually incredibly simple and a reliable tool for reducing cognitive complexity and boilerplate in C based projects.

ADTs are mostly string replacement on generic structs and unions, plus tagging on the union. It's not a complicated use of macros.