What are the differences between the C and C++ preprocessors? [duplicate]

久未见 提交于 2019-12-03 12:07:06

There are some differences between the C and C++ processors. Ignoring the differences in predefined macros and available system headers, some differences that come to mind in the current versions of C and of C++ are:

  • and and friends are operators, not identifiers, in C++. This means #define and && is valid in C, but not in C++, and means #if 1 and 2 is valid in C++, but not in C (unless and is suitably defined as a macro).
  • false and true are allowed in C++ #if expressions, but replaced by 0 (like all identifiers) in C. This means #if true/C++/#else/C/#endif expands to either C++, or C, depending on the language. Unlike and and friends, though, these are not operators, so may be redefined by #define in either language.
  • ::, .*, and ->* are tokens in C++. As a result of that, the ## operator can be used to form them in C++, but not in C.
  • Raw string literals are available in C++, but not in C. As a result, given a macro foo, R"x("foo")x" expands the macro in C, but not in C++.
  • Hexadecimal floating-point constants are available in C, but not in C++. As a result, given a macro foo, 0x1p+foo expands the macro in C++, but not in C.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!