21
General-purpose Multi-paradigm(ish) Efficient Employable Foundational Why C++? 6 / 26

localhost:1313/~anderson/teaching/3891/lecture/1/#p1anderson/teaching/3891/lecture/1/notes.pdf · where is a set of numbers Now: where is a set of... what? Invalid equation Type theory

  • Upload
    hanhi

  • View
    215

  • Download
    2

Embed Size (px)

Citation preview

General-purposeMulti-paradigm(ish)

Efficient

Employable

Foundational

Why C++?

6 / 26

History of C++

7 / 26

Significant language improvementsSafety features

Simpler and more complex!

Legacy

C++11

8 / 26

Topic 2:

Types

int i = 42;

double x = 3.1415926;string s = "Hello, world!";

Types

10 / 26

Set theory:

Russell's paradox:

Paradox!

History of types

11 / 26

Paradox!

12 / 26

where is a set of numbers

Now:

where is a set of... what?

Invalid equation

Type theory

13 / 26

Abstract machine:

Types in computing

14 / 26

32b int : 1,078,530,010

32b float : 3.1415926

Types in computing

15 / 26

mul ; unsigned integer multiplicationimul ; signed integer multiplicationfmul ; floating-point multiplicationmulps ; multiply packed single-precision floatsvfmaddpd ; fused multiply-add of packed double-pre...; even more!

Types in processors

16 / 26

Abstract machine:

Types in programming languages

17 / 26

Basic types:

bool b = true;char c = '?';int n = 1000000;double x = 3.1415926;string name = "Jonathan Anderson";

Types in C++

18 / 26

boolcharintfloatdouble

string

Specific integers

#include <stdint.h>

// Signed integers:int8_t a = 127; // 0x7fint16_t a = 32767; // 0x7fffint32_t a = 2147483647; // 0x7fffffffint64_t a = 9223372036854775807; // 0x7fffffffffffffff

// Unsigned integers:uint8_t a = 255; // 0xffuint16_t a = 65535; // 0xffffuint32_t a = 4294967295; // 0xffffffffuint64_t a = 18446744073709551615;// 0xffffffffffffffff

Types in C++

19 / 26

char int

int8_t a = /* ... */;

int8_t b = /* ... */;int8_t c = a + b;

Types in C++

20 / 26

bool b = true;

char c = '?';int n = 1000000;double x = 3.1415926;string name = "Jonathan Anderson";

What's in a name?

some characters and an integer length(roughly!)

string is a class that defines a new type

More complicated types

21 / 26

string

string

Representation

Operations

Types

22 / 26

Common operators:Operator Operation

Operator Operation

== Equals!= Not equal> Greater than< Less than>= Greater than or equal<= Less than or equal

Operations

23 / 26

truefalse

=

Common operators:Operator Operation Applies to

Operator Operation Applies to

+ Add int, doubleConcatenatestring

- Subtract int, double* Multiply int, double/ Divide int, double% Modulus int

Operations

24 / 26

truefalse

+

Common operators:Operator Operation Applies to

Operator Operation Applies to

+= Add & assign int, doubleAppend string

-= Subtract & assignint, double*= Multiply & assign int, double++ Increment int, double, iterators, ...-- Decrement int, double, iterators, ...

OperationsOperations

25 / 26

++ --

Given:

int a = 42;int b = 97;char c = '!';double x = 3.14;string s = "Hello, world!";

Try:

a + b; // Does this work? What does it mean?

s / a; // What compiler error do you see?

b % a; // What is this operation?

x % a; // What happens here?

s + a; // What is the result?

Exercise

26 / 26