Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is C code still considered C++?

Tags:

c++

c

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.

like image 306
Bill the Lizard Avatar asked Nov 20 '08 01:11

Bill the Lizard


People also ask

Is C still used in 2022?

C is one of the earliest and most widely used programming languages. C is the fourth most popular programming language in the world as of January 2022. Modern languages such as Go, Swift, Scala, and Python are not as popular as C.

Do people still use C for coding?

The C programming language will turn fifty years old in 2022. Yet despite its long history, C remains one of the top "most-used" programming languages in many "popular programming languages" surveys. For example, check out the TIOBE Index, which tracks the popularity of different programming languages.

Why is C coding called C?

C is a general purpose computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. It was named 'C' because many of its features were derived from an earlier language called 'B'.

Is C the same as C+?

C++ is a object oriented programming and supports OOPS concepts like polymorphism, encapsulation, and inheritance. C is a subset of C++. C++ is superset of C. All code of C can run in C++ but vice versa may or may not be true.


2 Answers

In general, yes C code is considered C++ code.

But C is not a proper subset in a strict sense. There are a couple of exceptions.

Here are some valid things in C that are not valid in C++:

int *new;//<-- new is not a keyword in C
char *p = malloc(1024); //void * to char* without cast 

There are more examples too, but you get the idea.

I previously wrote a more extensive answer in a similar question here.

like image 118
Brian R. Bondy Avatar answered Sep 28 '22 03:09

Brian R. Bondy


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.

like image 32
Josh Kelley Avatar answered Sep 28 '22 04:09

Josh Kelley