什么是C和C ++ preprocessors之间的区别是什么? [英] What are the differences between the C and C++ preprocessors?
问题描述
是否有行为之间的差异在 C 和C ++ preprocessors?
Are there any differences in behaviour between the C and C++ preprocessors?
They are defined by different passages of standards text (section 6.10 of the C standard and section 16 of the C++ standard).
我对问这个动机是一个制作单引号一个数字分隔这一建议最近被接纳进入C ++ 14扩展了C ++ preprocessor语法,以适应这种变化(具体而言,它扩展了的 PP-数的定义的),我想知道这是否引入了 C 和C ++ preprocessors之间的不兼容,如果是这样,无论是第一个特征这么做。
My motivation for asking this is that a proposal for making the single quote a digit separator that was recently accepted into C++14 extends the C++ preprocessor grammar to accomodate this change (specifically, it extends the definition of a pp-number), and I'm wondering whether this introduces an incompatibility between the C and C++ preprocessors, and if so, whether it's the first feature to do so.
推荐答案
有C和C ++处理器之间的一些差异。忽略predefined宏和可用的系统头,有些差异浮现在脑海中的C和C ++的当前版本的区别是:
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:
-
和
和朋友是运营商,不是标识符,在C ++。这意味着#define和&功放;&安培;
是在C有效,但不是在C ++和手段#如果1和2
在C ++有效,但不是在C(除非和
适当定义为宏)。 -
假
和真正
被允许在C ++#如果
前pressions,但0
替换(像所有的标识符),这意味着#如果真的
/C ++
/的#else
/C
/#ENDIF
扩展为C ++
或C
,根据不同的语言。不像和
和朋友,不过,这些都不是运营商,因此可以通过的#define
中的任何一种语言重新定义。 -
:
,*
和- > *。
是C ++令牌。作为一个结果是,##
操作符可以用来形成他们在C ++中,但不是在C。 - 原字符串在C ++的,但不是在C.结果给宏
富
,RX(富)x
扩大在C宏,但不是在C ++中。 - 十六进制浮点常数都可以在C,但不是在C ++中。其结果是,给定宏
富
,0x1p +富
宏扩展在C ++中,但不是在C.
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 (unlessand
is suitably defined as a macro).false
andtrue
are allowed in C++#if
expressions, but replaced by0
(like all identifiers) in C. This means#if true
/C++
/#else
/C
/#endif
expands to eitherC++
, orC
, depending on the language. Unlikeand
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.
这篇关于什么是C和C ++ preprocessors之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!