Scoping macros in C/C++


#1

Continuing the discussion from Heap Corruption with the SDK - How to resolve?:

Isn’t simple {} brackets enough to create a new scope?


#2

It’s an old trick. A simple {} causes code style issues sometimes. Explained here:

I don’t really use the do-while style and it’s best to try to avoid macros altogether IMHO. Sometimes they are unavoidable though.


#3

I agree: macros can be a pain to debug as well. I think they really shine for certain forms of error checking, though. With OpenGL, especially, I’m finding that approach near necessary.

Still, in this case one could define a function which simply takes SUResult as a param and perform the check that way (though early-outs would be lost in return).