News for hackers. Stuff that matters.
Re:Macros on Steroids: How pure C can benefit from metaprogr... by WalterBright on Thursday July 22, 2021 @12:40PM (#27921104)
My not-so-humble opinion is that if you're using the C preprocessor to do metaprogramming, you have outgrown C and need a more powerful language.
Re:Macros on Steroids: How pure C can benefit from metaprogr... by d_tr on Thursday July 22, 2021 @12:53PM (#27921299)
I humbly agree unless, of course, there is no other solution, e.g. lack of compilers on your platform.
Re:Macros on Steroids: How pure C can benefit from metaprogr... by WalterBright on Thursday July 22, 2021 @01:52PM (#27922078)
Even so, I used to do a lot of metaprogramming with the C preprocessor back in the day. Over time, I grew disillusioned with it and gradually removed it from my C code. It just wasn't worth it.

P.S. I also did metaprogramming in C by writing C programs to generate C code, such as converting an array of structs to multiple arrays, one for each field (for efficiency). This worked out fairly cleanly, but with D's ability to run functions at compile time, I was able to put this back into the main program.

Re:Macros on Steroids: How pure C can benefit from metaprogr... by touisteur on Thursday July 22, 2021 @04:57PM (#27924227)
I'm curious of your opinion about AdaCore CCG, an SPARK to C compiler, for targets that don't have an Ada compiler yet.
Re:Macros on Steroids: How pure C can benefit from metaprogr... by WalterBright on Thursday July 22, 2021 @05:02PM (#27924294)
I do not know enough about them to have a worthwhile opinion.
Re:Macros on Steroids: How pure C can benefit from metaprogr... by touisteur on Thursday July 22, 2021 @05:44PM (#27924725)
OK sorry :-) thanks
Re:Macros on Steroids: How pure C can benefit from metaprogr... by Hirrolot on Thursday July 22, 2021 @12:58PM (#27921379)
Re:Macros on Steroids: How pure C can benefit from metaprogr... by wudangmonk on Thursday July 22, 2021 @02:18PM (#27922379)
I agree that you shouldn't use the preprocessor for metaprogramming, it sucks. Switching to C++ is not a solution either since its template system is garbage for metaprogramming aswell.

Starting small with a small utility such as this one or creating one of your own is the best aproach in my opinion.

Re:Macros on Steroids: How pure C can benefit from metaprogr... by kaba0 on Friday July 23, 2021 @02:30AM (#27927831)
How are templates garbage? They are one of the most sophisticated metaprogramming tools out there I know of.