标签:每种 code ++ C++ 编译 valid behavior each
问题:
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.) (“有效”是指具有定义行为的标准代码,即不是特定于实现的/未定义的等。)
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: 为了使其成为合理/有用的比较(我试图学习一些实用的东西,而不是试图在问题中发现明显的漏洞),我们假设:
- Nothing preprocessor-related (which means no hacks with
#ifdef __cplusplus
, pragmas, etc.) 与预处理器无关(这意味着#ifdef __cplusplus
,#ifdef __cplusplus
不会引起黑客攻击) - Anything implementation-defined is the same in both languages (eg numeric limits, etc.) 实现定义的任何内容在两种语言中都是相同的(例如,数值限制等)
- We're comparing reasonably recent versions of each standard (eg say, C++98 and C90 or later) 我们正在比较每个标准的合理最新版本(例如C ++ 98和C90或更高版本)
If the versions matter, then please mention which versions of each produce different behavior. 如果版本很重要,请说明每个版本产生不同的行为。
解决方案:
参考一: https://stackoom.com/question/s4g8/以每种语言编译时-在C和C-中都有效的代码能否产生不同的行为参考二: https://oldbug.net/q/s4g8/Can-code-that-is-valid-in-both-C-and-C-produce-different-behavior-when-compiled-in-each-language 推荐:佳木斯SEO
标签:每种,code,++,C++,编译,valid,behavior,each 来源: https://www.cnblogs.com/vwvwvwgwg/p/12833480.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。