C and C++ have many differences, and not all valid C code is valid C++ code. C和C ++有不少区别,并不是全部有效的C代码都是有效的C ++代码。
(By "valid" I mean standard code with defined behavior, ie not implementation-specific/undefined/etc.) (“有效”是指具备定义行为的标准代码,即不是特定于实现的/未定义的等。) oop
Is there any scenario in which a piece of code valid in both C and C++ would produce different behavior when compiled with a standard compiler in each language? 在任何状况下,使用每种语言的标准编译器进行编译时,在C和C ++中都有效的一段代码会产生不一样的行为吗? 学习
To make it a reasonable/useful comparison (I'm trying to learn something practically useful, not to try to find obvious loopholes in the question), let's assume: 为了使其成为合理/有用的比较(我试图学习一些实用的东西,而不是试图在问题中发现明显的漏洞),咱们假设: spa
#ifdef __cplusplus
, pragmas, etc.) 与预处理器无关(这意味着#ifdef __cplusplus
, #ifdef __cplusplus
不会引发黑客攻击)