Redefine(#define) reserved c++ key word

前端 未结 4 1051
南方客
南方客 2021-01-26 12:20

Is it possible to redefine a c++ keyword using #define?

#ifdef int
#undef int 
#define int 2
#endif
int main(){
    //Do something with int
}

I

4条回答
  •  粉色の甜心
    2021-01-26 12:38

    Technically it works but it probably won't do you much good. If you want to use the standard C++ library you are not allowed define any of the keywords or any of a set of other names according to 17.6.4.3.1 [macro.names] paragraph 2:

    A translation unit shall not #define or #undef names lexically identical to keywords, to the identifiers listed in Table 3, or to the attribute-tokens described in 7.6.

提交回复
热议问题