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
不會引發黑客攻擊)