3 ms·
This is a joke, right?
by std_throwaway 9y ago
This is a joke, right?
- DSMan195276 9y agoWhy would it be a joke? Using `#define` for a string constant is perfectly reasonable for C code, IMO I'd argue it's the idiomatic and best way to do it. String constants that are `#define`d can take advantage of C's automatic string-literal concatenation, allowing you to avoid lots of unnecessary string operations in some cases. If you declare it as a pointer or array instead, then you can't do that.
- quotemstr 9y ago> Why would it be a joke? A certain influential segment of the C and C++ development community, the kind that tends to worship "best practices" and "consistency", has been preaching for years that C preprocessor macros are evil, even in cases where they allow for much clearer code. I'm not sure these people were born with the ability to experience joy.
- marcosdumay 9y agoThe biggest problem with C macros is that they are too opaque. The compilation stack will complain about code that is different from what you have, and leave you with little hint about what in your code is generating the broken code. It's also confusing when debugging. That said, yes they can lead to large gains so when they are worth it, go for them. Just mention in the documentation that they are macros, in big letters.
- magnetic 9y ago> Just mention in the documentation that they are macros, in big letters. The macros themselves are usually in BIG_LETTERS already... that generally gives it away.
- microtherion 9y agoAnd you pay for that with global namespace pollution and utter confusion if you ever reuse that name in a scope where you didn't even know you included the original header file.
- nom 9y agoi really hope it is