Annex C (informative) Compatibility [diff]

C.1 C++ and ISO C [diff.iso]

C.1.1 Clause [lex]: lexical conventions [diff.lex]

[lex.key]
Change: New Keywords
New keywords are added to C++; see [lex.key].
Rationale: These keywords were added in order to implement the new semantics of C++.
Effect on original feature: Change to semantics of well-defined feature. Any ISO C programs that used any of these keywords as identifiers are not valid C++ programs.
Difficulty of converting: Syntactic transformation. Converting one specific program is easy. Converting a large collection of related programs takes more work.
How widely used: Common.

[lex.ccon]
Change: Type of character literal is changed from int to char.
Rationale: This is needed for improved overloaded function argument type matching. For example:

int function( int i );
int function( char c );

function( 'x' );

It is preferable that this call match the second version of function rather than the first.
Effect on original feature: Change to semantics of well-defined feature. ISO C programs which depend on

sizeof('x') == sizeof(int)

will not work the same as C++ programs.
Difficulty of converting: Simple.
How widely used: Programs which depend upon sizeof('x') are probably rare.

Subclause [lex.string]:
Change: String literals made const.
The type of a string literal is changed from “array of char” to “array of const char”. The type of a char16_t string literal is changed from “array of some-integer-type” to “array of const char16_t”. The type of a char32_t string literal is changed from “array of some-integer-type” to “array of const char32_t”. The type of a wide string literal is changed from “array of wchar_t” to “array of const wchar_t”.
Rationale: This avoids calling an inappropriate overloaded function, which might expect to be able to modify its argument.
Effect on original feature: Change to semantics of well-defined feature.
Difficulty of converting: Syntactic transformation. The fix is to add a cast:

char* p = "abc";                // valid in C, invalid in C++
void f(char*) {
  char* p = (char*)"abc";       // OK: cast added
  f(p);
  f((char*)"def");              // OK: cast added
}


How widely used: Programs that have a legitimate reason to treat string literals as pointers to potentially modifiable memory are probably rare.