C++ Standards and the Move to C++11
Compatibility is checked feature by feature, not by assuming that a program written in one language or standard will survive the move to another.
Is Every C Program Also a C++ Program?
C and C++ are closely related, and this closeness leads many programmers to assume that code written in one language can be moved to the other without changes. This article tests that assumption. The short answer is that it is not safe to assume it. C and C++ are separate languages, each with its own standards, and code that is correct in one can be rejected in the other.
What do you think happens?
If a C program compiles cleanly under a C compiler, will it also compile as C++?
Reveal answer
No, because C and C++ are separate languages with their own standards
Code valid in C is not automatically valid in C++. Each standard adds features and sometimes removes or changes behavior, so compatibility has to be checked feature by feature.
C and C++ as Two Languages
The central idea is that C and C++ are two languages, not two versions of one language. C89, C99, and C11 are different standards of the C language. C++ and C++11 belong to the C++ language. Each language has its own standards, and each standard can add new features while sometimes also removing or changing behavior that earlier code relied on.
The map shows why the two languages cannot be treated as one. Every C standard sits under the C language and every C++ standard sits under the C++ language. A feature that appears under a C standard only does not automatically exist in C++. That is the point to hold onto as you read the rest of this article.
What Each Standard Adds or Changes
A standard is not only a list of additions. Because each standard adds features and sometimes removes or changes behavior, the same piece of code can be correct under one standard and wrong under another. This is why the question to ask is not whether a feature is good or bad. The question to ask is whether the target standard supports it.
Compatibility is not a yes-or-no property of a whole program. It is decided feature by feature. A program may use several features, and each one must be supported by the standard you are compiling against. A single unsupported feature is enough to make the whole program fail to compile under that standard.
Compatibility is checked feature by feature, not by assuming that a program written in one language or standard will survive the move to another.
Reading the Comparison Table
The main tool for this work is a comparison table. Each row names a language feature, and the table places features in columns according to which standards support them. The columns cover C89 only, C99 only, C++ only, features shared between certain standards, C++11 only, C11 only, and features shared by C++11 and C11. Reading the table correctly means matching each feature in the right-hand column with its standard marker on the left.
| Feature | Standard it belongs to | Carries into C++? |
|---|---|---|
| Algol-style function definitions | C99 | No. The feature is part of C99 but is not part of C++. |
| Using restrict as an identifier | C99 feature | Yes. This C99 feature is accepted in C++. |
Two C99 features and whether C++ accepts them
The table shows that not every C99 feature is incompatible. Some features from C99 carry into C++ without trouble, while others do not. This is why a blanket rule such as all C99 code is C++ code, or no C99 code is C++ code, would be wrong. Each row must be read on its own.
Tracing a Feature Through the Check
Deciding whether Algol-style function definitions survive the move to C++
A C program uses Algol-style function definitions, which are a C99 feature. Will the code survive being compiled as C++?
- 1Read the feature
The code uses Algol-style function definitions.
- 2Find the marker
The comparison table marks this feature as belonging to C99.
- 3Check the target
The feature is part of C99 but is not part of C++, so C++ does not support it.
- 4Decide
Because one unsupported feature is enough to fail, the code does not survive the move to C++.
The program is rejected under C++ because Algol-style function definitions are not supported there.
Now apply the same four steps to a feature that carries over. Using restrict as an identifier is a C99 feature, and the table shows that C++ accepts it. A program that relies only on this feature passes the check for C++. The method is the same in both cases. Only the result changes, because the target standard either supports the feature or it does not.
Mistakes Beginners Make with Standards
Common mistake Believing that C++ is simply the next step after C
What it looks likeAssuming that because a program is valid C, it must also be valid C++.
Why it failsC and C++ are separate languages with their own standards. Every valid C program is not automatically a valid C++ program.
Do this insteadTreat C and C++ as two languages and check each feature against the C++ standard before assuming the code will compile.
Common mistake Assuming all C code is compatible with C++
What it looks likeMoving a C file into a C++ project without checking which standard its features belong to.
Why it failsSome features, such as Algol-style function definitions, are part of C99 but not part of C++. One such feature is enough to make the code fail.
Do this insteadRead the comparison table, match each feature to its standard marker, and confirm that the target standard supports it.
Common mistake Treating every C99 feature as incompatible
What it looks likeRejecting code that uses restrict as an identifier simply because it comes from C99.
Why it failsSome C99 features are accepted in C++, so the source does not support a blanket rule either way.
Do this insteadDecide feature by feature. Keep features that the table shows are supported and replace the ones it shows are not.
Common mistake Judging a feature as good or bad instead of asking whether the target standard supports it
Checking Your Understanding
Using the comparison table, decide whether each of these two features would survive a move from C99 code to C++: Algol-style function definitions, and using restrict as an identifier. For each one, state the standard marker you matched and your decision.
Hints
- Start by matching the feature name to its row in the table.
- Check the standard marker first, then ask whether C++ supports that feature.
- Algol-style function definitions are part of C99 but not part of C++.
A teammate says, since C++ is the newer version of C, our C program will compile as C++ without changes. Write a short reply that corrects this belief and describes the four-step check you would use to test it.
Hints
- Explain that C and C++ are separate languages with their own standards.
- Describe reading the feature, finding its marker, checking the target standard, and deciding.
Key Takeaways
- C and C++ are separate languages, and C89, C99, and C11 are standards of C while C++ and C++11 belong to C++.
- Each standard adds features and sometimes removes or changes behavior, so compatibility must be checked feature by feature.
- Features such as Algol-style function definitions are part of C99 but not part of C++, so valid C code can fail to compile as C++.
- A comparison table lets you match each feature to its standard marker and decide whether the target standard supports it.
- Do not assume C++ is simply the next step after C, and do not assume all C code is compatible with C++.