Affected subclause: [basic.def]
Change:
C++ does not have βtentative definitionsβ as in C
.
E.g., at file scope,
int i;
int i;
is valid in C, invalid in C++
. 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
. For example,
struct X { int i; struct X* next; };
static struct X a;
static struct X b = { 0, &a };
static struct X a = { 1, &b };
Rationale:
This avoids having different initialization rules for
fundamental types and user-defined types
. Effect on original feature:
Deletion of semantically well-defined feature
. Difficulty of converting:
Semantic transformation
. 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
. Affected subclause: [basic.scope]
Change:
A
struct is a scope in C++, not in C
. Rationale:
Class scope is crucial to C++, and a struct is a class
. Effect on original feature:
Change to semantics of well-defined feature
. Difficulty of converting:
Semantic transformation
. 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. The latter is probably rare
. 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
. 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
. This feature allows the user to put const objects in source files that are included
in more than one translation unit
. Effect on original feature:
Change to semantics of well-defined feature
. Difficulty of converting:
Semantic transformation
. Affected subclause: [basic.types]
Change:
C allows βcompatible typesβ in several places, C++ does not
.
For example,
otherwise-identical
struct types with different tag names
are βcompatibleβ in C but are distinctly different types
in C++
. Rationale:
Stricter type checking is essential for C++
. Effect on original feature:
Deletion of semantically well-defined feature
. Difficulty of converting:
Semantic transformation
. The βtypesafe linkageβ mechanism will find many, but not all,
of such problems
. Those problems not found by typesafe linkage will continue to
function properly,
according to the βlayout compatibility rulesβ of this
document
.