Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
CPlusPlusNotesForProfessionals.pdf
Скачиваний:
47
Добавлен:
20.05.2023
Размер:
5.11 Mб
Скачать

Chapter 136: C incompatibilities

This describes what C code will break in a C++ compiler.

Section 136.1: Reserved Keywords

The first example are keywords that have a special purpose in C++: the following is legal in C, but not C++.

int class = 5

These errors are easy to fix: just rename the variable.

Section 136.2: Weakly typed pointers

In C, pointers can be cast to a void*, which needs an explicit cast in C++. The following is illegal in C++, but legal in C:

void* ptr;

int* intptr = ptr;

Adding an explicit cast makes this work, but can cause further issues.

Section 136.3: goto or switch

In C++, you may not skip initializations with goto or switch. The following is valid in C, but not C++:

goto foo;

int skipped = 1; foo;

These bugs may require redesign.

GoalKicker.com – C++ Notes for Professionals

643