4 ms·
Having worked with script generated C++ in the past, this looks annoying as hell to debug. Whereas macros and templates have compiler support to give line numb
by CoolGuySteve 8y ago
Having worked with script generated C++ in the past, this looks annoying as hell to debug.
Whereas macros and templates have compiler support to give line numbers inside the macro/template, generated code errors have an extra step of having to look at the C++, find the error in the generator, rinse, repeat.
Lambdas are better, but if you have to repeat yourself in a way that's too syntactically weird for a template or lambda, you can "#define MY_MACRO(...)" and end it with "#undef MY_MACRO" to keep the namespace clean.
- InitialLastName 8y agoSometimes you're working with a language that doesn't support a sophisticated preprocessor, or where it's convenient to be able to use a higher-level language to generate constants/do math at compile time.
- ironmagma 8y agoFunny you say that, as we use Cog to avoid having to deal with C++ templates and their associated pains. The nice thing about Cog is that it operates like any Linux command-line tool, just at the text level, and as a result, if something has gone wrong at the compilation phase, you can see what was fed into the compiler to see what exactly was generated. Interpreting C++ template error outputs is an art in and of itself.
- ahaferburg 8y agoAFAIK, VC doesn't support line numbers in macros. If you want better line numbers generated code, you can generate #line pragmas. Typically, I don't debug any generated code though, because it's only boilerplate that has been tested a million times already. So that's a bit of a non-issue in the real world.