4 ms·
C11 added _Generic to language, but turns out metaprogramming by inhumanely abusing the preporcessor is possible even in pure C99: meet Metalang99 library. I'm
by jnspts 3y ago
C11 added _Generic to language, but turns out metaprogramming by inhumanely abusing the preporcessor is possible even in pure C99: meet Metalang99 library.
I'm actually working on a library doing just that! It's still in very (very) early development, but maybe someone may find it to be interesting. [1]
Link [2] is the implementation of a vector. Link [3] is a test file implementing a vector of strings.
[1]: https://github.com/jenspots/libwheel https://github.com/jenspots/libwheel
[2]: https://github.com/jenspots/libwheel/blob/main/include/wheel/vec/impl.h https://github.com/jenspots/libwheel/blob/main/include/wheel...
[3]: https://github.com/jenspots/libwheel/blob/main/tests/impl/string.h https://github.com/jenspots/libwheel/blob/main/tests/impl/st...
- burstmode 3y agoC++ Metaprogramming is also just a bunch sugarcoated preprocessor macros and it was never someting else.
- idispatch 3y agoThis is plainly not true
- WalterBright 3y agoThe fundamental difference is the C preprocessor is actually a language independent of C. They follow their own grammars, syntax, semantics, symbol tables, etc., and do not communicate with each other.
- cempaka 3y agoThe downvotes make me laugh, I did something pretty similar not long after the _Generic keyword came out and remember getting a pretty icy reception even though I was pretty up front about how painful and crufty it is. https://abissell.com/2014/01/16/c11s-_generic-keyword-macro-applications-and-performance-impacts/ https://abissell.com/2014/01/16/c11s-_generic-keyword-macro-...