Home >Backend Development >C++ >What Breaking Changes Should I Be Aware Of When Migrating Code to C 11?

What Breaking Changes Should I Be Aware Of When Migrating Code to C 11?

Susan Sarandon
Susan SarandonOriginal
2024-12-24 17:19:28487browse

What Breaking Changes Should I Be Aware Of When Migrating Code to C  11?

Breaking Changes in C 11

C 11 introduced significant changes that may impact the compilation of existing code, including the following:

Core Language

  • The introduction of explicit operator bool() in the standard library, replacing instances of operator void*(). This change may cause code that previously relied on implicit conversions to fail to compile.
  • New keywords, including alignas, alignof, char16_t, constexpr, and nullptr, may conflict with existing identifiers in code that did not follow naming conventions.
  • The behavior of integer division has changed, as C 11 always rounds the result towards 0, while C 03 allowed for rounding towards 0 or negative infinity.
  • Implicitly-declared special member functions, such as constructors or destructors, are now defined as deleted if their implicit definition would have been ill-formed, which may cause code using these functions in certain contexts to become invalid.
  • User-declared destructors have an implicit exception specification, meaning they cannot throw exceptions. Code that relies on destructors throwing exceptions may need to be modified.
  • Dependent calls of functions with internal linkage are now allowed, which may change the resolution of overloaded functions in templates.

Library Changes

  • Identifiers added to the C standard library in C 11 may conflict with existing identifiers in code that used headers with the same names.
  • The swap function has been moved from the header to the header. Code that includes may need to be updated to include instead.
  • The global namespace posix is now reserved for standardization. Code that defines identifiers in this namespace may need to be modified.
  • Macros named override, final, carries_dependency, or noreturn are invalid in C 11. Code that defines these macros may need to be updated.

The above is the detailed content of What Breaking Changes Should I Be Aware Of When Migrating Code to C 11?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn