Is a C++ preprocessor identical to a C preprocessor?

前端 未结 3 1024
情书的邮戳
情书的邮戳 2020-11-28 12:37

I am wondering how different the preprocessors for C++ and C are.

The reason for the question is this question on a preprocessor-specific question w

3条回答
  •  情歌与酒
    2020-11-28 13:24

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

    • C99 N1256 draft 6.10.8 "Predefined macro names"
    • C++11 N3337 draft 16.8 "Predefined macro names"

    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::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.

提交回复
热议问题