3 ms·
In C++, anyway. C’s expressiveness, on the other hand, is pretty weak, and a preprocessor is very useful there. A better preprocessor (a C code generator, effe
by Koshkin 5y ago
In C++, anyway. C’s expressiveness, on the other hand, is pretty weak, and a preprocessor is very useful there.
A better preprocessor (a C code generator, effectively) would be a simple program that would interpret the <% and %> brackets or similar (by “inverting” them). It is very powerful paradigm.
- WalterBright 5y agoYou're talking about metaprogramming. I've seen C code that does metaprogramming with the preprocessor. If you want to use metaprogramming, you've outgrown C and should consider a more powerful language. There are plenty to pick from. DasBetterC, for example.
- Koshkin 5y agoBut the <%-preprocessor would be the most powerful metaprogramming tool, would it not? Simply because the programmer would have at their disposal the power of the entire real programming language as opposed to being limited to whatever template language happens to be built in. For instance, if I want to generate a piece of code to define an enum and, at the same time, have a method to serialize it (say, into XML), then with <% it is a trivial task, whereas in C# I need to define and use some weird "attribute" class, while C++ offers me no way whatsoever to accomplish this, with all its metaprogramming power. Is D different in this regard?
- WalterBright 5y agoD can indeed do it. But that is way too advanced for what C is. I'll repeat that if metaprogramming is important to you, you need a more advanced language. Why are you using C if you want advanced features?
- Koshkin 5y agoBecause it seems to me that metaprogramming/preprocessing/code generation is orthogonal to how advanced or complex the language is.