3 ms·
Has there been any notion of a replacement Meta/Macro language for C? Something open source. Of course pre-preprocessing one's files and the complexity that mig
by DubiousPusher 11y ago
Has there been any notion of a replacement Meta/Macro language for C? Something open source. Of course pre-preprocessing one's files and the complexity that might add to the build system are unattractive but I'd still be interested if someone has attacked this problem.
- pcwalton 11y agoThe module and template features (along with static if, if the committees figure out what to do in that area) in the newest versions of C++ together get pretty close to replacing the C preprocessor.
- ArkyBeagle 11y agoStatic if can be ( crudely ) synthesized today.
- ctstover 11y agoMy school of thought would be to limit it to just #include, #if, #else, #end, and non-recursive single word only #define / #undef. Force everything to be 1 per single line, and call it a day. Macros should always be the absolute last resort to doing anything. Stepping through code in gdb with some "creative" macro-based API is almost as bad as C++.
- ArkyBeagle 11y agoI've seen 'C' macros used to do template-ey things that probably reinforced the readability of the code ( once you get used to the fact that the macros were there at all ) . More modern compilers allow using non-static "const" constructs to do much of the same, which is a great improvement. To wit: #define in_bounds(lower,x,upper) ((x <upper) && (x >lower)) vs. const bool in_bounds = ((x > lower) && ( x < upper )); Macros can be used effectively for reduction in strength, so long as you're not too clever about it.
- DubiousPusher 11y agoYou'll forgive me if my knowledge is a bit dated. I largely work on tools integration these days and don't do much in the way of framework development but aren't macros pretty much the defacto way of doing reflection/rtti. Actually, almost every mature framework I've worked with in the past used macros to markup class properties, register types, etc.
- ArkyBeagle 11y agoMuch of what makes 'C' annoying can be made less painful by referring to static/const struct tables/arrays. Those are a prime candidate for generation. You don't have to keep the preprocessing of files as part of the mainline build, but there's something to be said for it - sort of "make GENERATE_ALL_THE_THINGS" might run the preprocessing { Python/Tcl/Perl/bash/even 'C' } scripts for you. If the generators just emit .h files, that can be pretty good. You're still left with something #ifdef-ey to select them, based on #defines or -D options. You might even go so far as to dynamically load these tables if that can make sense. The ld linker can directly link in blobs.