Sometimes to make things easier to write and read, I write some local #define macros within functions (for example, #define O_REAL Ogre::Real)
.
Unfortunately, #define
s do not respect scoping rules. #define
s that are not #undef
'd will affect all code after them. Additionally, if code before you defines the same macro name, you'll have problems. In C++ you can usually avoid needing to use such local macros with local typedefs
and references. For example, you could do:
void foo() {
typedef Ogre::Real O_REAL;
// ...
}
This will respect scoping rules. For variables you can use references:
void foo() {
int &BAR = Foo::quux::baz::static_bar;
// ...
}