C/C++区别

本文主要参考了C++标准委员会出品的 Mix-c-and-cpp 和 Learning C++ if you already know C 两个链接对应的一些问答内容,加上我个人的理解完成。本文先会说明C++和C的发展历史和它们之间关系,然后从编程范式上提纲挈领地总结一下表达下我个人的感受,之后从几个区别点来具体说明它们的不同。有不准确或疏漏的地方还请大家指正,谢谢。

然后,关于C++语言标准参考文档我推荐 cppreference c++ language document ;关于C语言标准参考文档我推荐 cppreference c language document ;有兴趣的朋友可以看看,当然也可以把它们当成参考文档查阅用。

然后现在最新的C++标准是C++1x,C标准是C1x,希望大家都可以用最新的标准,因为最新的标准填上了很多坑。另外,提醒一下,其实C++包括两个部分:C++语言(language)部分和C++库(library)部分,学C++这两部分都要学好;学习C语言也是一样。

本文的主要内容包括四个部分。第一部分是 背景:C1x与C++1x是一对兄弟,C95是他们的爹 ,第二部分是 C/C++区别-从编程范式上来讲 ,第三部分是 C/C++区别-重要的(区别0-9) , 第四部分是 C/C++区别-其他(区别10-12和其他) 。本文最末给出了一些相关的参考文章。

(一/四) 背景:C1x与C++1x是一对兄弟,C95是他们的爹


引用一下 Learning C++ if you already know C 中的一段话,概括一下C++1x/C1x和C95的关系。C++98和C99其实已经有不兼容的地方了,那么在之后的进程中这些不兼容的点会更多;因为事实上在语言层面上,C++新标准和C新标准制定的是不同语言的标准,只不过它们的语法有许多相同或者相似的部分。然后下面引用的段落中的几个链接为C++之父推荐看的文档或书籍,大家感兴趣的话,可以看一看这些资料。

C++ is a direct descendant of C95 (C90 plus an Amendment) that retains almost all of C95 as a subset. C++ provides stronger type checking than C and directly supports a wider range of programming styles than C. C++ is “a better C” in the sense that it supports the styles of programming done using C with better type checking and more notational support (without loss of efficiency). In the same sense, ANSI C90/C95 is a better C than K&R C. In addition, C++ supports data abstraction, object-oriented programming, and generic programming (see The C++ Programming Language; Appendix B discussing compatibility issues is available for downloading).

We have never seen a program that could be expressed better in C95 than in C++ (and we don’t think such a program could exist – every construct in C95 has an obvious C++ equivalent). However, there still exist a few environments where the support for C++ is so weak that there is an advantage to using C instead. There aren’t all that many of those left, though; see Stroustrup’s (incomplete) compilers list.

For a discussion of the design of C++ including a discussion of its relationship with C see The Design and Evolution of C++.

Please note that “C” in the paragraphs above refers to Classic C and C95 (C90 with an Amendment). C++ is not a descendant of C99; rather, both are derived from C95. C++11 adopted all of C99’s preprocessor extensions and library extensions, but not C99’s new language features, so language features like the restrict keyword that were added in C99 are generally not part of ISO C++. Here is a description of the differences between C++98 and C99.

(二/四) C/C++区别-从编程范式上来讲


从编程范式上来讲,C语言是一种遵循面向过程,或者俗称(imperative programming/procedure programming)编程范式的程序设计语言,其关注点在于对解决问题的Solver的抽象,所以C语言更接近于汇编。

而C++与其设计理念不同,C++试图允许大家使用各种编程范式:

  • 比如首先支持使用C语言中的面向过程的编程范式。
  • 比如支持面向对象的编程范式,使得我们可以开始抽象问题本身,通过定义抽象数据类型(Abstract Data Type)来抽象问题࿰

你可能感兴趣的:(C++,linux,编程语言,C++,linux,C语言,编程语言,程序员)