C language is not a strict subset of C + +

Source: Internet
Author: User
Tags array definition function prototype

is C language a subset of C + +? is C + + extensible and contains all C language content on the basis of C?

Reply:

From a practical point of view, C + + belongs to a superset of C language, which is basically compatible with ANSI C. However, some features of c are not supported in C + + from a compilation perspective. In contrast, ANSI C inherits several features of C + +, including prototypes and constants. Therefore, these two languages are not another superset or subset, and they differ in the definition of some common constructs. Despite these differences, many C programs can be compiled in the C + + environment, and many of the latest compilers provide both C and C + + compilation modes. However, do not compile the C code completely as C + + code, or you will get an error when encountering an incompatibility problem.

C + + has been improved as follows.

The C + + array definition is limited. In the C language, the array is initialized without count the group overflow judgment, which makes it easier for the array not to have enough space to hold the data and produce an error. C + + has made some improvements, and expressions like char str[3]= "Jim" are considered to be a mistake, but it is legal in the C language.

In C + +, declarative statements can be interspersed between statements. As you know, in C, all declarations in a block of statements must precede all statements, and C + + removes this restriction so that declaration statements can be interspersed between statements.

C + + is the most important improvement on the object-oriented expansion. C language is a process-oriented structured language, and C + + is an object-oriented language, it adds the object-oriented mechanism on the basis of C language, which makes C + + more perfect and practical than C language.

There are limitations in C + + that do not exist in the language.

In C + +, user code cannot call the main function main () function, but in c it is possible (but rarely).

The declaration of a function prototype in C + + is strict, the requirement must be complete, and in C language is not so strict.

In C + +, the name of a type defined by a TypeDef cannot conflict with an existing structure name, but it is allowed in C language.

C + + prescribes stricter type handling, for example, when the void* pointer is assigned to another type of pointer, C + + requires mandatory type conversion, which is not necessary in C.

C + + has different meanings in C language:

C + + has expanded the keywords in the language, adding at least more than 10. These keywords can be used as identifiers in the C language, but if such C-language code is compiled using the C + + compiler, an error message is generated.

In C + +, the structure name of the inner scope hides the same object name in outer space, which is not the case in the C language.

In C + +, annotations can use the "//" notation, which is not available in the C language.

Comments

In general, C is the predecessor of C + +, which describes only part of the difference. As can be seen from the above, C + + does not have some of the most basic problems in C language to improve, it still retains the C language of many flaws, and on this basis, and piled up a lot of complex things. However, despite a number of shortcomings, C and C + + are widely used, which also shows the value of its existence.

There are many differences between C and C + +, and it is necessary to analyze the difference between the two by actual programming, and to stay alert and avoid mistakes when using each other.

---references: http://book.51cto.com/art/201203/326393.htm

C language is not a strict subset of C + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.