C ++ contains the whole C language?

In the tutorials, I read that C ++ contains the entire C programming language.

However, I also read in places like this , which

If you learn C ++, you will eventually learn most of C with some differences between the languages ​​that you will learn over time.

So my question is only this:

If I know C ++ well, can I eventually learn the “real” C language (without any “differences”) because the full C90 language is included in C ++ 11?

+10
c ++ c
Jul 19 '15 at 20:04
source share
5 answers

No, C ++ is not a superset of C. While C ++ contains most of C, there is a subtle difference that can bite you very much where you least expect them. Here are some examples:

  • C has the concept of pre-definitions that does not exist in C ++.
  • C does not require explicit conversion when assigning void pointers to variables of a particular type.
  • C has different rules regarding const propagation.
  • C has something called the "implicit int rule", which, although canceled with C99, appears several times and needs to be considered.
  • The C preprocessor has some functions that the C ++ preprocessor does not have.
  • The C language has two styles of function definition: K & R-style and Stroustrup style. C ++ has a Stroustrup style.
  • The vocabulary rules for C and C ++ are different, since none of them is a subset of the other
  • C and C ++ have different sets of reserved words. This can cause strange errors because the identifier is not allowed in another language.
  • While C ++ used almost all the functions of ANSI C (C89), many functions were added to C in subsequent standard versions that are not available in C ++.
  • C ++ has a different syntax, even for some parts that are not new. For example, a ? b : c = d a ? b : c = d is a syntax error in C, but parsed as a ? b : (c = d) a ? b : (c = d) in C ++.
  • C ensures that &*E matches exactly E , even if E is a null pointer. C ++ does not have such a guarantee.
  • In C, a string literal initializing an array of characters can initialize an array that is at least longer than a string without the \0 byte. (ie char foo[3] = "bar" is legal). In C ++, an array must be at least as long as the string contains byte \0 .
  • In C, a character literal of type 'A' is of type int . In C ++, it is of type char .
  • C has a special rule allowing the introduction of type rights in unions. C ++ is missing this language, creating code such as

     union intfloat { int i; float f; } fi; fi.f = 1.0; printf("%d\n", fi.i); 

    undefined.

+15
Jul 19 '15 at 20:08
source share

If I know C ++ well, I will eventually learn the “real” C language (without any “differences”)

If you learn C ++ correctly, you probably won't need to use many of the standard methods used in C. Theoretically, you can program almost all C in C ++, with the exceptions already introduced. However, in reality you should not or should not. This is due to the fact that C ++ is another language that, when used, optimally uses an excellent set of tools.

Besides the basic elements, such as the general syntax and fundamental types, these are two separately developing languages, and they should be approached (studied, programmed) as such.

+5
Jul 19 '15 at 20:10
source share

In a broad sense, C ++ is essentially C, with the addition of a whole group of objects oriented to objects. Almost all the code you could write in C would also compile and work in C ++.

However, there are several angles of languages ​​where there are differences. Over time, their number is gradually growing, but languages ​​do not change fast enough to be a serious problem.

If you study only C ++, then yes, you will eventually learn almost all aspects of the C language. If you become an expert in C ++, you can identify and understand places where there are small differences between the similar parts of C and C ++ .

+4
Jul 19 '15 at 20:12
source share

I'm not sure what "differences" may exist ...

For example > like this :

In C:
void foo () means "a function foo that takes an indefinite number of arguments of an unspecified type"
[...]
In C ++:
void foo () means "function foo without arguments"

+2
Jul 19 '15 at 20:09
source share

If you learn C ++ first, you can pretty easily learn the entire C library. Some of the syntax is slightly different from other smaller differences. As with KerrekSB, an example of this might be customization rules of the type and implicit assignment from void. There are many more, but in the end you can study them. It is basically like learning English slang.

-one
Jul 19 '15 at 20:11
source share



All Articles