Alex Rivera | Logout

Is C code still considered C++?

Asked 2008-11-20T01:36:10.187
10

The comment to this answer got me wondering. I've always thought that C was a proper subset of C++, that is, any valid C code is valid C++ code by extension. Am I wrong about that? Is it possible to write a valid C program that is not valid C++ code?

EDIT: This is really similar to, but not an exact duplicate of this question.

c++ c
Edit
Report

4 Answers

12

Also note that C99 adds several features which aren't permitted in C++ (or are only supported using vendor extensions), such as builtin _Complex and _Imaginary data types, variable-length arrays (arrays sized at runtime rather than compile time), flexible array members (arrays declared as the last member of a struct that may contain an unspecified number of elements), and more.

For the exhaustive list of incompatibilities between C and C++, including changes with C99, see http://david.tribble.com/text/cdiffs.htm.

answered 2008-11-20T03:03:55.410
5

A couple of other things that are valid C but not C++:

int func();
func(0,0); //Error in C++, but not in C

Also don't underestimate the impact of C++ having more keywords:

int new;  //Obviously an error in C++
answered 2008-11-20T02:33:57.013
5

One thing that sets the two apart and comes up in day to day development is linkage and function name mangling. A C function compiled with a C compiler is not accessible to C++ unless the prototype is marked up with extern "C".

answered 2008-11-20T02:34:41.257
1

I think it may be more correct to say that ANSI C is a subset of C++. Not K&R C.

answered 2008-11-20T01:54:52.007

Your Answer