Init
This commit is contained in:
202
cppdraft/diff/basic.md
Normal file
202
cppdraft/diff/basic.md
Normal file
@@ -0,0 +1,202 @@
|
||||
[diff.basic]
|
||||
|
||||
# Annex C (informative) Compatibility [[diff]](./#diff)
|
||||
|
||||
## C.7 C++ and C [[diff.iso]](diff.iso#diff.basic)
|
||||
|
||||
### C.7.3 [[basic]](basic "6 Basics"): basics [diff.basic]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/compatibility.tex#L2851)
|
||||
|
||||
**Affected subclause:** [[basic.def]](basic.def)
|
||||
|
||||
|
||||
**Change:** C++ does not have âtentative definitionsâ as in C.
|
||||
|
||||
[*Example [1](#example-1)*:
|
||||
|
||||
At file scope,int i;int i; is valid in C, invalid in C++[.](#1.sentence-1)
|
||||
|
||||
â *end example*]
|
||||
|
||||
This makes it impossible to define
|
||||
mutually referential file-local objects with static storage duration,
|
||||
if initializers are restricted to the syntactic forms of C[.](#1.sentence-2)
|
||||
|
||||
[*Example [2](#example-2)*: struct X { int i; struct X* next; };
|
||||
|
||||
static struct X a;static struct X b = { 0, &a };static struct X a = { 1, &b }; â *end example*]
|
||||
|
||||
|
||||
|
||||
|
||||
**Rationale:** This avoids having different initialization rules for
|
||||
fundamental types and user-defined types[.](#1.sentence-3)
|
||||
|
||||
|
||||
|
||||
|
||||
**Effect on original feature:** Deletion of semantically well-defined feature[.](#1.sentence-4)
|
||||
|
||||
|
||||
|
||||
|
||||
**Difficulty of converting:** Semantic transformation[.](#1.sentence-5)
|
||||
|
||||
In C++, the initializer for one of a set of
|
||||
mutually-referential file-local objects with static storage
|
||||
duration must invoke a function
|
||||
call to achieve the initialization[.](#1.sentence-6)
|
||||
|
||||
|
||||
|
||||
|
||||
**How widely used:** Seldom[.](#1.sentence-7)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/compatibility.tex#L2888)
|
||||
|
||||
**Affected subclause:** [[basic.scope]](basic.scope)
|
||||
|
||||
|
||||
**Change:** A struct is a scope in C++, not in C.
|
||||
|
||||
[*Example [3](#example-3)*:
|
||||
|
||||
struct X {struct Y { int a; } b;};struct Y c; is valid in C but not in C++, which would require X::Y c;[.](#2.sentence-1)
|
||||
|
||||
â *end example*]
|
||||
|
||||
|
||||
|
||||
**Rationale:** Class scope is crucial to C++, and a struct is a class[.](#2.sentence-3)
|
||||
|
||||
|
||||
|
||||
|
||||
**Effect on original feature:** Change to semantics of well-defined feature[.](#2.sentence-4)
|
||||
|
||||
|
||||
|
||||
|
||||
**Difficulty of converting:** Semantic transformation[.](#2.sentence-5)
|
||||
|
||||
|
||||
|
||||
|
||||
**How widely used:** C programs use struct extremely frequently, but the
|
||||
change is only noticeable when struct, enumeration, or enumerator
|
||||
names are referred to outside the struct[.](#2.sentence-6)
|
||||
|
||||
The latter is probably rare[.](#2.sentence-7)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/compatibility.tex#L2912)
|
||||
|
||||
**Affected subclause:** [[basic.link]](basic.link) [also [[dcl.type]](dcl.type "9.2.9 Type specifiers")]
|
||||
|
||||
**Change:** A name of file scope that is explicitly declared const, and not explicitly
|
||||
declared extern, has internal linkage, while in C it would have external linkage[.](#3.sentence-2)
|
||||
|
||||
|
||||
|
||||
|
||||
**Rationale:** Because const objects may be used as values during translation in
|
||||
C++, this feature urges programmers to provide an explicit initializer
|
||||
for each const object[.](#3.sentence-3)
|
||||
|
||||
This feature allows the user to put const objects in source files that are included
|
||||
in more than one translation unit[.](#3.sentence-4)
|
||||
|
||||
|
||||
|
||||
|
||||
**Effect on original feature:** Change to semantics of well-defined feature[.](#3.sentence-5)
|
||||
|
||||
|
||||
|
||||
|
||||
**Difficulty of converting:** Semantic transformation[.](#3.sentence-6)
|
||||
|
||||
|
||||
|
||||
|
||||
**How widely used:** Seldom[.](#3.sentence-7)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/compatibility.tex#L2929)
|
||||
|
||||
**Affected subclause:** [[basic.start.main]](basic.start.main)
|
||||
|
||||
|
||||
**Change:** The main function cannot be called recursively and cannot have its address taken[.](#4.sentence-1)
|
||||
|
||||
|
||||
|
||||
|
||||
**Rationale:** The main function may require special actions[.](#4.sentence-2)
|
||||
|
||||
|
||||
|
||||
|
||||
**Effect on original feature:** Deletion of semantically well-defined feature[.](#4.sentence-3)
|
||||
|
||||
|
||||
|
||||
|
||||
**Difficulty of converting:** Trivial: create an intermediary function such asmymain(argc, argv)[.](#4.sentence-4)
|
||||
|
||||
|
||||
|
||||
|
||||
**How widely used:** Seldom[.](#4.sentence-5)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/compatibility.tex#L2942)
|
||||
|
||||
**Affected subclause:** [[basic.types]](basic.types)
|
||||
|
||||
|
||||
**Change:** C allows âcompatible typesâ in several places, C++ does not[.](#5.sentence-1)
|
||||
|
||||
|
||||
|
||||
|
||||
For example,
|
||||
otherwise-identical struct types with different tag names
|
||||
are âcompatibleâ in C but are distinctly different types
|
||||
in C++[.](#5.sentence-2)
|
||||
|
||||
|
||||
|
||||
|
||||
**Rationale:** Stricter type checking is essential for C++[.](#5.sentence-3)
|
||||
|
||||
|
||||
|
||||
|
||||
**Effect on original feature:** Deletion of semantically well-defined feature[.](#5.sentence-4)
|
||||
|
||||
|
||||
|
||||
|
||||
**Difficulty of converting:** Semantic transformation[.](#5.sentence-5)
|
||||
|
||||
The âtypesafe linkageâ mechanism will find many, but not all,
|
||||
of such problems[.](#5.sentence-6)
|
||||
|
||||
Those problems not found by typesafe linkage will continue to
|
||||
function properly,
|
||||
according to the âlayout compatibility rulesâ of this
|
||||
document[.](#5.sentence-7)
|
||||
|
||||
|
||||
|
||||
|
||||
**How widely used:** Common[.](#5.sentence-8)
|
||||
Reference in New Issue
Block a user