Top Banner
Overview of C++: Design Goals Douglas C. Schmidt [email protected] www.dre.vanderbilt.edu/~schmidt Professor of Computer Science Institute for Software Integrated Systems Vanderbilt University Nashville, Tennessee, USA
26

Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Sep 20, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of C++: Design Goals

Douglas C. Schmidt

[email protected]

www.dre.vanderbilt.edu/~schmidt

Professor of Computer Science

Institute for Software Integrated Systems

Vanderbilt University Nashville, Tennessee, USA

Page 2: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

2

Learning Objectives in this Part of the Lesson• Recognize the key components of C++

• Know strategies for learning C++

• Understand C++ design goals

Page 3: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

3

C++ Design Goals

Page 4: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

4

C++ Design Goals

• As with C, run-time efficiency is important

Page 5: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

5See www.youtube.com/watch?v=G5zCGY0tkq8

• As with C, run-time efficiency is important

• Zero-overhead abstraction

• e.g., classes with constructors & destructors, inheritance, generic programming, functional programming techniques, etc.

C++ Design Goals

Page 6: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

6

• As with C, run-time efficiency is important

• Zero-overhead abstraction

• Direct mapping to hardware

• e.g., no virtual machine overhead for instructions & native data types

C++ Design Goals

Page 7: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

7

C++ Design Goals

• As with C, run-time efficiency is important

• Zero-overhead abstraction

• Direct mapping to hardware

• No complicated run-time libraries,managed environments, or virtual machines

• Unlike other languages, e.g., Ada, Java, C#, etc.

See en.wikipedia.org/wiki/Gordian_Knot

Page 8: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

8

C++ Design Goals

• As with C, run-time efficiency is important

• Zero-overhead abstraction

• Direct mapping to hardware

• No complicated run-time libraries,managed environments, or virtual machines

• No language-specific support for persistence, garbage collection, or networking in C++

Page 9: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

9

C++ Design Goals

• As with C, run-time efficiency is important

• Zero-overhead abstraction

• Direct mapping to hardware

• No complicated run-time libraries,managed environments, or virtual machines

• No language-specific support for persistence, garbage collection, or networking in C++

• Additional support for threading,synchronization, & parallelismwas added beginning w/C++11

See www.modernescpp.com/index.php/c-core-guidelines-rules-for-concurrency-and-parallelism

Page 10: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

10

C++ Design Goals

• As with C, run-time efficiency is important

• Zero-overhead abstraction

• Direct mapping to hardware

• No complicated run-time libraries,managed environments, or virtual machines

• No language-specific support for persistence, garbage collection, or networking in C++

• Many libraries exist that provide these capabilities

See www.dre.vanderbilt.edu/ACE & www.boost.org

Page 11: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

11

C++ Design Goals

• Compatibility w/C libraries & traditional development tools is emphasized

Page 12: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

12

C++ Design Goals

• Compatibility w/C libraries & traditional development tools is emphasized, e.g.,

• Object code reuse

• e.g., the storage layout of structs is compatible with C

Page 13: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

13

C++ Design Goals

• Compatibility w/C libraries & traditional development tools is emphasized, e.g.,

• Object code reuse

• e.g., the storage layout of structs is compatible with C

• Supports the standard ANSI C library, UNIX & Windows system calls via extern blocks, etc.

See www.dre.vanderbilt.edu/~schmidt/ACE/book1

Page 14: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

14

C++ Design Goals

• Compatibility w/C libraries & traditional development tools is emphasized, e.g.,

• Object code reuse

• C++ works with the “make” familyof (re)compilation build tools

See www3.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html

Page 15: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

15

C++ Design Goals

• An initial design goal was for C++ to be “as close to C as possible, but no closer”

Page 16: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

16

C++ Design Goals

• An initial design goal was for C++ to be “as close to C as possible, but no closer”

• i.e., C++ is not a proper superset of C

• Backwards compatibility with C is not entirely maintained

See www.stroustrup.com/hopl2.pdf

Page 17: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

17

C++ Design Goals

• An initial design goal was for C++ to be “as close to C as possible, but no closer”

• i.e., C++ is not a proper superset of C

• Backwards compatibility with C is not entirely maintained

See en.wikipedia.org/wiki/Compatibility_of_C_and_C++

void *ptr;

/* Implicit conversion

from void* to int* */

int *i = ptr;

/* Implicit conversion

from void* to int* */

int *j =

malloc(5 * sizeof *j);

Valid in C, but not in C++

Page 18: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

18

C++ Design Goals

• An initial design goal was for C++ to be “as close to C as possible, but no closer”

• i.e., C++ is not a proper superset of C

• Backwards compatibility with C is not entirely maintained

See en.wikipedia.org/wiki/Compatibility_of_C_and_C++

void *ptr;

/* Implicit conversion

from void* to int* */

int *i = ptr;

/* Implicit conversion

from void* to int* */

int *j =

malloc(5 * sizeof *j);

Valid in C, but not in C++

void *ptr;

int *i = (int *)ptr;

int *j = (int *)

malloc(5 * sizeof *j);

Valid in C++ & C

Page 19: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

19

C++ Design Goals

• An initial design goal was for C++ to be “as close to C as possible, but no closer”

• i.e., C++ is not a proper superset of C

• Backwards compatibility with C is not entirely maintained

See en.wikipedia.org/wiki/Compatibility_of_C_and_C++

void *ptr;

/* Implicit conversion

from void* to int* */

int *i = ptr;

/* Implicit conversion

from void* to int* */

int *j =

malloc(5 * sizeof *j);

Valid in C, but not in C++

void *ptr;

int *i = (int *)ptr;

int *j = (int *)

malloc(5 * sizeof *j);

void *ptr;

auto i =

reinterpret_cast<int *>

(ptr);

auto j = new int[5];

Preferred in C++

Valid in C++ & C

Page 20: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

20

C++ Design Goals

• An initial design goal was for C++ to be “as close to C as possible, but no closer”

• i.e., C++ is not a proper superset of C

• Backwards compatibility with C is not entirely maintained

• Typically not a problem in practice...

Page 21: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

21

C++ Design Goals

• Later C++ design goals focus on generic programming & helping developers to use modern C++ effectively

Page 22: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

22

C++ Design Goals

• Later C++ design goals focus on generic programming & helping developers to use modern C++ effectively

• Generic programming generalizes software components so that they can be easily reused in many situations

See www.boost.org/community/generic_programming.html

Page 23: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

23

C++ Design Goals

• Later C++ design goals focus on generic programming & helping developers to use modern C++ effectively

• Generic programming generalizes software components so that they can be easily reused in many situations

• C++ templates enable generic programming since they generalize without sacrificing efficiency

See www.boost.org/community/generic_programming.html

template

<typename InputIterator,

typename OutputIterator>

OutputIterator

copy(InputIterator first,

InputIterator last,

OutputIterator result) {

while (first != last)

*result++ = *first++;

return result;

}

int a[] = {1, 2, 3, ...};

vector<int> v = {1, 2, 3, ...};

copy(a, a + sizeof(a)/sizeof(*a), ostream_iterator<int>(cout));

copy(v.begin(), v.end(), ostream_iterator<int>(cout));

Page 24: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

24

C++ Design Goals

• Later C++ design goals focus on generic programming & helping developers to use modern C++ effectively

• Generic programming generalizes software components so that they can be easily reused in many situations

• The C++ core guidelines are a set ofidioms documented to help developers efficiently and consistently write type & resource safe C++ programs

See isocpp.github.io/CppCoreGuidelines

Page 25: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

25

C++ Design Goals

• Later C++ design goals focus on generic programming & helping developers to use modern C++ effectively

• Generic programming generalizes software components so that they can be easily reused in many situations

• The C++ core guidelines are a set ofidioms documented to help developers efficiently and consistently write type & resource safe C++ programs

See isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines.html#Rr-newdelete

Page 26: Overview of C++: Design Goalsschmidt/cs251/2020-PDFs/design-goals.pdf · C++ Design Goals •Later C++ design goals focus on generic programming & helping developers to use modern

Overview of Douglas C. Schmidt

26

End of C++ Design Goals