Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What prevents C++ from being a strict superset of C? [duplicate]

Tags:

c++

c

Possible Duplicate:
“C subset of C++” -> Where not ? examples ?

I'm aware that C++ is not a strict superset of C. What language features prevent C++ from being a superset of C?

like image 690
Mike Avatar asked Sep 23 '10 09:09

Mike


People also ask

Is C++ a strict superset of C?

C++ is a superset of C. All your C programs will work without any modification in this environment. However, we recommend that you get accustomed to new styles and techniques of C++ from day one.

Is Objective-C superset of C?

Objective-C is a thin layer atop C and is a "strict superset" of C, meaning that it is possible to compile any C program with an Objective-C compiler and to freely include C language code within an Objective-C class. Objective-C derives its object syntax from Smalltalk.

Is all C code valid Objective-C?

"Objective-C is a superset of C" means that every valid C program is a valid Objective-C program (with the same meaning).

Is C++ a subset of C?

C++ language is a subset of the C language. C++ was first designed as an extension of C language. Thus in addition to the procedural language features derived from C, C++ also supports object-oriented programming features like inheritance, polymorphism, abstraction, encapsulation, etc.


2 Answers

The elephant in the room: the following is valid C but not valid C++.

int typename = 1; 

Substitute your favorite C++ reserved word.

like image 145
Konrad Rudolph Avatar answered Sep 18 '22 13:09

Konrad Rudolph


C++ also does not support variable-length arrays, where:

int array[n]; 

is valid in C, but not C++. A C++ version of the above would be:

int *array = new int[n];   ... delete [] array; 
like image 38
Alexander Rafferty Avatar answered Sep 17 '22 13:09

Alexander Rafferty