3 ms·
STL is not a problem in C land and fishy macros don't make it past code review in my book :-). I don't disagree on the usefulness of teasing your brain with th
by weland 12y ago
STL is not a problem in C land and fishy macros don't make it past code review in my book :-).
I don't disagree on the usefulness of teasing your brain with these things once in a while. However, I think the best way to ensure you don't hit bugs caused by such things is to avoid the situation altogether.
- JoeAltmaier 12y agoIt doesn't have to be a very fishy macro at all to be problematic. How about #define Sum(a,b) a+b This of course fails in any context where the precedence of '+' doesn't match your intent e.g. Sum(1,5)7 becomes 1+57 Do you remember to always define your expression macros with parentheses? Any time you didn't do that, you have a bug.
- lmm 12y ago> Do you remember to always define your expression macros with parentheses? Yes - that's a necessary part of being idiomatic. Any macro that's defined without brackets sticks out like a sore thumb, and won't pass code review, even if it's (initially) used in a place where they wouldn't be necessary.
- weland 12y ago> Do you remember to always define your expression macros with parentheses? Oh, yes! No parentheses around elements of a macro definition is an obvious sound of trouble and looks very wrong on my retina. I do agree, though, that if I somehow forgot to do that (tired? nervous?), that would be a bug that's difficult to spot. Point taken :). That's what code reviews are for, but there isn't always time or availability for one, sadly.