← Back to context

Comment by WalterBright

4 years ago

You'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.

But 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?

  • D 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?

    • Because it seems to me that metaprogramming/preprocessing/code generation is orthogonal to how advanced or complex the language is.