Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
C++
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===With C=== {{Main|Compatibility of C and C++}} C++ is often considered to be a superset of [[C (programming language)|C]] but this is not strictly true.<ref name="superset">{{cite web |url=http://www.stroustrup.com/bs_faq.html#C-is-subset |title=Bjarne Stroustrup's FAQ β Is C a subset of C++? |access-date=5 May 2014 |archive-date=6 February 2016 |archive-url=https://web.archive.org/web/20160206214150/http://www.stroustrup.com/bs_faq.html#C-is-subset |url-status=live }}</ref> Most C code can easily be made to compile correctly in C++ but there are a few differences that cause some valid C code to be invalid or behave differently in C++. For example, C allows implicit conversion from <syntaxhighlight lang="C++" inline>void*</syntaxhighlight> to other pointer types but C++ does not (for type safety reasons). Also, C++ defines many new keywords, such as <syntaxhighlight lang="C++" inline>new</syntaxhighlight> and <syntaxhighlight lang="C++" inline>class</syntaxhighlight>, which may be used as identifiers (for example, variable names) in a C program. Some incompatibilities have been removed by the 1999 revision of the C standard ([[C99]]), which now supports C++ features such as line comments (<syntaxhighlight lang="C++" inline>//</syntaxhighlight>) and declarations mixed with code. On the other hand, C99 introduced a number of new features that C++ did not support that were incompatible or redundant in C++, such as [[variable-length array]]s, native complex-number types (however, the <syntaxhighlight lang="C++" inline>std::complex</syntaxhighlight> class in the C++ standard library provides similar functionality, although not code-compatible), designated initializers, [[C syntax#Compound literals|compound literals]], and the <syntaxhighlight lang="C++" inline>restrict</syntaxhighlight> keyword.<ref>{{cite web |url=http://home.datacomm.ch/t_wolf/tw/c/c9x_changes.html |title=C9X β The New C Standard |access-date=27 December 2008 |archive-date=21 June 2018 |archive-url=https://web.archive.org/web/20180621084656/http://home.datacomm.ch/t_wolf/tw/c/c9x_changes.html |url-status=live }}</ref> Some of the C99-introduced features were included in the subsequent version of the C++ standard, [[C++11#Improved C compatibility|C++11]] (out of those which were not redundant).<ref>{{cite web |title=C++0x Support in GCC |url=https://gcc.gnu.org/projects/cxx0x.html |access-date=12 October 2010 |archive-date=21 July 2010 |archive-url=https://web.archive.org/web/20100721215324/http://gcc.gnu.org/projects/cxx0x.html |url-status=live }}</ref><ref>{{cite web |title=C++0x Core Language Features In VC10: The Table |url=https://blogs.msdn.com/b/vcblog/archive/2010/04/06/c-0x-core-language-features-in-vc10-the-table.aspx |access-date=12 October 2010 |archive-date=21 August 2010 |archive-url=https://web.archive.org/web/20100821114635/http://blogs.msdn.com/b/vcblog/archive/2010/04/06/c-0x-core-language-features-in-vc10-the-table.aspx |url-status=live }}</ref><ref>{{cite web |url=https://clang.llvm.org/cxx_status.html |title=Clang - C++98, C++11, and C++14 Status |publisher=Clang.llvm.org |date=12 May 2013 |access-date=10 June 2013 |archive-date=4 July 2013 |archive-url=https://web.archive.org/web/20130704124639/http://clang.llvm.org/cxx_status.html |url-status=live }}</ref> However, the C++11 standard introduces new incompatibilities, such as disallowing assignment of a string literal to a character pointer, which remains valid C. To intermix C and C++ code, any function declaration or definition that is to be called from/used both in C and C++ must be declared with C linkage by placing it within an <syntaxhighlight style=white-space:nowrap lang="C++" inline>extern "C" {/*...*/}</syntaxhighlight> block. Such a function may not rely on features depending on [[name mangling]] (i.e., function overloading).
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
C++
(section)
Add topic