Skip to Content
C++语言导学(原书第2版)
book

C++语言导学(原书第2版)

by 本贾尼 斯特劳斯特鲁普
August 2021
Intermediate to advanced
450 pages
5h 35m
Chinese
Pearson
Content preview from C++语言导学(原书第2版)

16.3.1 C和C++是兄弟

经典C有两个主要后代:ISO C和ISO C++。多年以来,两种语言在以不同的步调,沿着不同的方向发展着。造成的一个结果就是它们都支持传统C风格编程,但支持的方式有着细微不同。所产生的不兼容会使某些人非常苦恼——同时使用C和C++的人、使用一种语言编写程序但用到另一种语言编写的库的人以及为C和C++编写库和工具的人。

我为何会说C和C++是兄弟呢?毕竟C++很明显是C的后代。但是,请看下面简化后的家谱。

在此图中,实线表示大量特性的继承,短杠虚线表示主要特性的借用,而点虚线表示次要特性的借用。从中可以看出,ISO C和ISO C++是K&R C[Kernighan,1978]的两个主要后代,因此它们是兄弟。两者的发展过程中都从经典C继承了关键特性,但又都不是100%兼容经典C。“经典C”一词是我从Dennis Ritchie的显示器上贴的便条中挑出来的。它大致相当于K&R C加上枚举和struct赋值两个特性。BCPL是在[Richards,1980]中定义的,C89是在[C90]中定义的。

注意,C和C++的差别并不一定是C++演化过程中对C特性做出改变的结果。有很多不兼容的例子是在将C++中已存在很久的特性引入C时产生的。例如,T*到void*的赋值以及全局const的链接[Stroustrup,2002]。有时,一个特性都已经成为ISO C++标准的一部分,才被引入C并产生了不兼容,例如inline的含义。

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

软件开发实践:项目驱动式的Java开发指南

软件开发实践:项目驱动式的Java开发指南

Raoul-Gabriel Urma, Richard Warburton
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey
Python机器学习案例精解

Python机器学习案例精解

Posts & Telecom Press, Yuxi (Hayden) Liu

Publisher Resources

ISBN: 9787111633280