C ++预处理器是否与C预处理器相同?

时间:2011-02-23 00:00:07

标签: c++ c standards c-preprocessor

我想知道C ++和 C 的预处理器有多么不同。

问题的原因是this question关于特定于预处理器的问题,其中解决问题的标准段落具有不同的措辞(和不同的段落编号),并且也是{{1 C ++中的}和true个关键字。

那么,是否存在更多差异,或者这是唯一的区别。

问题的扩展将是C ++预处理器和 C 预处理器以不同方式发出的源文件。

3 个答案:

答案 0 :(得分:17)

C ++ 03预处理器(至少打算)类似于C99之前的C预处理器。虽然措辞和段落编号略有不同,但我知道两者之间唯一的技术差异是C ++预处理器处理有向图和通用字符名称,这些名称在C中不存在。

从C99开始,C预处理器添加了一些在当前版本的C ++中不存在的新功能(例如,可变参数宏)。我不记得肯定,但不相信添加了有向图。

我相信C ++ 0x会再次排队(至少那是意图)。同样,段落编号和措辞也不尽相同,但我认为其意图是它们的工作方式相同(除了保留上述差异外)。

答案 1 :(得分:4)

它们应该是相同的:C ++ 98和C ++ 03应该与C90匹配,而C ++ 0x应该与C99匹配。但是,措辞中可能存在错误。

答案 2 :(得分:4)

Predefined macros differ between the preprocessors, mostly for obvious language feature differences. E.g. compare:

In particular:

  • C requires you not to define __cplusplus, C++ uses it to represent the version
  • C uses __STDC__ to represent the version, C++ says is implementation defined and uses __cplusplus instead
  • C has __STDC_IEC_559__ and __STDC_IEC_559_COMPLEX__ to indicate floating point characteristics, C++ does not and seems replace that with the per type std::numeric_limits<float>::is_iec559 constants
  • C does not have the macros prefixed with __STDCPP: _STDCPP_STRICT_POINTER_SAFETY__ and __STDCPP_THREADS__

As mentioned by DevSolar, C11 added many more defines which are not part of C++11.