Do I need to #undef a local #define? Is there such a thing as a local define?

后端 未结 6 1067
刺人心
刺人心 2021-02-05 12:45

Sometimes to make things easier to write and read, I write some local #define macros within functions (for example, #define O_REAL Ogre::Real).

6条回答
  •  悲哀的现实
    2021-02-05 12:58

    The scope of a macro is part of compilation unit that comes after #define, up until the end of the unit (which is to say, until the end of .cpp file). However Visual C++ has a pair of #pragma push_macro/pop_macro that can be used in a case where macro definitions overlap. You can push previous definition, define your own, use it, and when you decide just pop previous definition.

提交回复
热议问题