TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Code behaving differently in C90, C99, C11, C++98, and C++11

134 pointsby Kristine1975almost 9 years ago

5 comments

pcwaltonalmost 9 years ago
I think this goes to show that <i>theoretical</i> backwards compatibility doesn&#x27;t matter nearly as much as <i>de facto</i> backwards compatibility. As this IOCCC entry shows, every single C++ revision has been a breaking change to the previous revision. A naive interpretation of this would say &quot;well, C++ is not useful for enterprise use because the language is constantly changing&quot;. But in reality it doesn&#x27;t matter, because the backwards-incompatible parts affect code nobody would intentionally write (excluding IOCCC entries!), and as a result C++ has a deserved reputation for stability.
评论 #12154478 未加载
评论 #12154849 未加载
评论 #12156528 未加载
评论 #12154321 未加载
gpderettaalmost 9 years ago
Because of SFINAE for expressions added in C++11 (which gives the capability to test at compile time whether an arbitrary expression is valid or not), technically <i>any</i> change to the language or standard library can change the behaviour of a valid C++ program.
pveierlandalmost 9 years ago
One behavioral change in C++11 is the noexcept specifier; with user-defined destructors defaulting to noexcept(true). If you have pre-C++11 code throwing exceptions from within a destructor, e.g. to signal a violated postcondition contract, the program will terminate when such an exception is thrown after compiling the program as C++11.<p>Updating the code to function under C++11 requires adding a noexcept(false) specification to throwing destructors.
bluejekyllalmost 9 years ago
This is really cool. Though, I have to say, I was hoping that it was examples of undefined behavior and how that changes between versions and compilers.<p>But still, pretty neat in terms of features.
omoikanealmost 9 years ago
Summary of all tricks used can be found here: <a href="http:&#x2F;&#x2F;uguu-archive.appspot.com&#x2F;fuuko&#x2F;source&#x2F;c_version.c" rel="nofollow">http:&#x2F;&#x2F;uguu-archive.appspot.com&#x2F;fuuko&#x2F;source&#x2F;c_version.c</a>
评论 #12156849 未加载