6.s096 lecture 1: compilation pipelineopen.gnu.ac.kr/.../slides_c/mit6_s096_iap13_lec1.pdf · 2017....

Post on 23-Sep-2020

0 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

6s096 Introduction to C and C++

1

Why 2

1

You seek performance

3

1

You seek performance ldquozero-overhead principlerdquo

4

2 You seek to interface

directly with hardware

5

3

Thatrsquos kinda it

6

C a nice way to avoid writing assembly language directly

7

C++ responds to the demands of maintaining large C projects

8

C++11 responds to the demands of

maintaining large C++ projects

9

Maintain power and flexibility of what came before

10

Today CompilationPipeline

11

Source Code

Program 12

mainc prog

int a = 1 ) prog

gcc -o prog mainc 13

mainc

int a = 1 prog

) prog main2c

int b = 2

gcc -o prog mainc main2c 14

$ gcc -o prog mainc $ prog Hello World $

15

DONE $ gcc -o prog mainc $ prog Hello World $

16

ldquoTo debug the sausage one must see how it is maderdquo

mdashSomeone probably

17

Mainjava Mainclass

( int a = 1 java Main

18

Mainjava Mainclass

(

mainpyc

(

a = 1

mainpy

int a = 1 java Main

python mainpy

19

Mainjava Mainclass

int a = 1 (

maino

)

prog

(

mainpyc

(

int a = 1

mainc

a = 1

mainpy

int a = 1 java Main

python mainpy

prog

20

21

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Why 2

1

You seek performance

3

1

You seek performance ldquozero-overhead principlerdquo

4

2 You seek to interface

directly with hardware

5

3

Thatrsquos kinda it

6

C a nice way to avoid writing assembly language directly

7

C++ responds to the demands of maintaining large C projects

8

C++11 responds to the demands of

maintaining large C++ projects

9

Maintain power and flexibility of what came before

10

Today CompilationPipeline

11

Source Code

Program 12

mainc prog

int a = 1 ) prog

gcc -o prog mainc 13

mainc

int a = 1 prog

) prog main2c

int b = 2

gcc -o prog mainc main2c 14

$ gcc -o prog mainc $ prog Hello World $

15

DONE $ gcc -o prog mainc $ prog Hello World $

16

ldquoTo debug the sausage one must see how it is maderdquo

mdashSomeone probably

17

Mainjava Mainclass

( int a = 1 java Main

18

Mainjava Mainclass

(

mainpyc

(

a = 1

mainpy

int a = 1 java Main

python mainpy

19

Mainjava Mainclass

int a = 1 (

maino

)

prog

(

mainpyc

(

int a = 1

mainc

a = 1

mainpy

int a = 1 java Main

python mainpy

prog

20

21

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

1

You seek performance

3

1

You seek performance ldquozero-overhead principlerdquo

4

2 You seek to interface

directly with hardware

5

3

Thatrsquos kinda it

6

C a nice way to avoid writing assembly language directly

7

C++ responds to the demands of maintaining large C projects

8

C++11 responds to the demands of

maintaining large C++ projects

9

Maintain power and flexibility of what came before

10

Today CompilationPipeline

11

Source Code

Program 12

mainc prog

int a = 1 ) prog

gcc -o prog mainc 13

mainc

int a = 1 prog

) prog main2c

int b = 2

gcc -o prog mainc main2c 14

$ gcc -o prog mainc $ prog Hello World $

15

DONE $ gcc -o prog mainc $ prog Hello World $

16

ldquoTo debug the sausage one must see how it is maderdquo

mdashSomeone probably

17

Mainjava Mainclass

( int a = 1 java Main

18

Mainjava Mainclass

(

mainpyc

(

a = 1

mainpy

int a = 1 java Main

python mainpy

19

Mainjava Mainclass

int a = 1 (

maino

)

prog

(

mainpyc

(

int a = 1

mainc

a = 1

mainpy

int a = 1 java Main

python mainpy

prog

20

21

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

1

You seek performance ldquozero-overhead principlerdquo

4

2 You seek to interface

directly with hardware

5

3

Thatrsquos kinda it

6

C a nice way to avoid writing assembly language directly

7

C++ responds to the demands of maintaining large C projects

8

C++11 responds to the demands of

maintaining large C++ projects

9

Maintain power and flexibility of what came before

10

Today CompilationPipeline

11

Source Code

Program 12

mainc prog

int a = 1 ) prog

gcc -o prog mainc 13

mainc

int a = 1 prog

) prog main2c

int b = 2

gcc -o prog mainc main2c 14

$ gcc -o prog mainc $ prog Hello World $

15

DONE $ gcc -o prog mainc $ prog Hello World $

16

ldquoTo debug the sausage one must see how it is maderdquo

mdashSomeone probably

17

Mainjava Mainclass

( int a = 1 java Main

18

Mainjava Mainclass

(

mainpyc

(

a = 1

mainpy

int a = 1 java Main

python mainpy

19

Mainjava Mainclass

int a = 1 (

maino

)

prog

(

mainpyc

(

int a = 1

mainc

a = 1

mainpy

int a = 1 java Main

python mainpy

prog

20

21

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

2 You seek to interface

directly with hardware

5

3

Thatrsquos kinda it

6

C a nice way to avoid writing assembly language directly

7

C++ responds to the demands of maintaining large C projects

8

C++11 responds to the demands of

maintaining large C++ projects

9

Maintain power and flexibility of what came before

10

Today CompilationPipeline

11

Source Code

Program 12

mainc prog

int a = 1 ) prog

gcc -o prog mainc 13

mainc

int a = 1 prog

) prog main2c

int b = 2

gcc -o prog mainc main2c 14

$ gcc -o prog mainc $ prog Hello World $

15

DONE $ gcc -o prog mainc $ prog Hello World $

16

ldquoTo debug the sausage one must see how it is maderdquo

mdashSomeone probably

17

Mainjava Mainclass

( int a = 1 java Main

18

Mainjava Mainclass

(

mainpyc

(

a = 1

mainpy

int a = 1 java Main

python mainpy

19

Mainjava Mainclass

int a = 1 (

maino

)

prog

(

mainpyc

(

int a = 1

mainc

a = 1

mainpy

int a = 1 java Main

python mainpy

prog

20

21

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

3

Thatrsquos kinda it

6

C a nice way to avoid writing assembly language directly

7

C++ responds to the demands of maintaining large C projects

8

C++11 responds to the demands of

maintaining large C++ projects

9

Maintain power and flexibility of what came before

10

Today CompilationPipeline

11

Source Code

Program 12

mainc prog

int a = 1 ) prog

gcc -o prog mainc 13

mainc

int a = 1 prog

) prog main2c

int b = 2

gcc -o prog mainc main2c 14

$ gcc -o prog mainc $ prog Hello World $

15

DONE $ gcc -o prog mainc $ prog Hello World $

16

ldquoTo debug the sausage one must see how it is maderdquo

mdashSomeone probably

17

Mainjava Mainclass

( int a = 1 java Main

18

Mainjava Mainclass

(

mainpyc

(

a = 1

mainpy

int a = 1 java Main

python mainpy

19

Mainjava Mainclass

int a = 1 (

maino

)

prog

(

mainpyc

(

int a = 1

mainc

a = 1

mainpy

int a = 1 java Main

python mainpy

prog

20

21

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

C a nice way to avoid writing assembly language directly

7

C++ responds to the demands of maintaining large C projects

8

C++11 responds to the demands of

maintaining large C++ projects

9

Maintain power and flexibility of what came before

10

Today CompilationPipeline

11

Source Code

Program 12

mainc prog

int a = 1 ) prog

gcc -o prog mainc 13

mainc

int a = 1 prog

) prog main2c

int b = 2

gcc -o prog mainc main2c 14

$ gcc -o prog mainc $ prog Hello World $

15

DONE $ gcc -o prog mainc $ prog Hello World $

16

ldquoTo debug the sausage one must see how it is maderdquo

mdashSomeone probably

17

Mainjava Mainclass

( int a = 1 java Main

18

Mainjava Mainclass

(

mainpyc

(

a = 1

mainpy

int a = 1 java Main

python mainpy

19

Mainjava Mainclass

int a = 1 (

maino

)

prog

(

mainpyc

(

int a = 1

mainc

a = 1

mainpy

int a = 1 java Main

python mainpy

prog

20

21

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

C++ responds to the demands of maintaining large C projects

8

C++11 responds to the demands of

maintaining large C++ projects

9

Maintain power and flexibility of what came before

10

Today CompilationPipeline

11

Source Code

Program 12

mainc prog

int a = 1 ) prog

gcc -o prog mainc 13

mainc

int a = 1 prog

) prog main2c

int b = 2

gcc -o prog mainc main2c 14

$ gcc -o prog mainc $ prog Hello World $

15

DONE $ gcc -o prog mainc $ prog Hello World $

16

ldquoTo debug the sausage one must see how it is maderdquo

mdashSomeone probably

17

Mainjava Mainclass

( int a = 1 java Main

18

Mainjava Mainclass

(

mainpyc

(

a = 1

mainpy

int a = 1 java Main

python mainpy

19

Mainjava Mainclass

int a = 1 (

maino

)

prog

(

mainpyc

(

int a = 1

mainc

a = 1

mainpy

int a = 1 java Main

python mainpy

prog

20

21

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

C++11 responds to the demands of

maintaining large C++ projects

9

Maintain power and flexibility of what came before

10

Today CompilationPipeline

11

Source Code

Program 12

mainc prog

int a = 1 ) prog

gcc -o prog mainc 13

mainc

int a = 1 prog

) prog main2c

int b = 2

gcc -o prog mainc main2c 14

$ gcc -o prog mainc $ prog Hello World $

15

DONE $ gcc -o prog mainc $ prog Hello World $

16

ldquoTo debug the sausage one must see how it is maderdquo

mdashSomeone probably

17

Mainjava Mainclass

( int a = 1 java Main

18

Mainjava Mainclass

(

mainpyc

(

a = 1

mainpy

int a = 1 java Main

python mainpy

19

Mainjava Mainclass

int a = 1 (

maino

)

prog

(

mainpyc

(

int a = 1

mainc

a = 1

mainpy

int a = 1 java Main

python mainpy

prog

20

21

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Maintain power and flexibility of what came before

10

Today CompilationPipeline

11

Source Code

Program 12

mainc prog

int a = 1 ) prog

gcc -o prog mainc 13

mainc

int a = 1 prog

) prog main2c

int b = 2

gcc -o prog mainc main2c 14

$ gcc -o prog mainc $ prog Hello World $

15

DONE $ gcc -o prog mainc $ prog Hello World $

16

ldquoTo debug the sausage one must see how it is maderdquo

mdashSomeone probably

17

Mainjava Mainclass

( int a = 1 java Main

18

Mainjava Mainclass

(

mainpyc

(

a = 1

mainpy

int a = 1 java Main

python mainpy

19

Mainjava Mainclass

int a = 1 (

maino

)

prog

(

mainpyc

(

int a = 1

mainc

a = 1

mainpy

int a = 1 java Main

python mainpy

prog

20

21

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Today CompilationPipeline

11

Source Code

Program 12

mainc prog

int a = 1 ) prog

gcc -o prog mainc 13

mainc

int a = 1 prog

) prog main2c

int b = 2

gcc -o prog mainc main2c 14

$ gcc -o prog mainc $ prog Hello World $

15

DONE $ gcc -o prog mainc $ prog Hello World $

16

ldquoTo debug the sausage one must see how it is maderdquo

mdashSomeone probably

17

Mainjava Mainclass

( int a = 1 java Main

18

Mainjava Mainclass

(

mainpyc

(

a = 1

mainpy

int a = 1 java Main

python mainpy

19

Mainjava Mainclass

int a = 1 (

maino

)

prog

(

mainpyc

(

int a = 1

mainc

a = 1

mainpy

int a = 1 java Main

python mainpy

prog

20

21

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Source Code

Program 12

mainc prog

int a = 1 ) prog

gcc -o prog mainc 13

mainc

int a = 1 prog

) prog main2c

int b = 2

gcc -o prog mainc main2c 14

$ gcc -o prog mainc $ prog Hello World $

15

DONE $ gcc -o prog mainc $ prog Hello World $

16

ldquoTo debug the sausage one must see how it is maderdquo

mdashSomeone probably

17

Mainjava Mainclass

( int a = 1 java Main

18

Mainjava Mainclass

(

mainpyc

(

a = 1

mainpy

int a = 1 java Main

python mainpy

19

Mainjava Mainclass

int a = 1 (

maino

)

prog

(

mainpyc

(

int a = 1

mainc

a = 1

mainpy

int a = 1 java Main

python mainpy

prog

20

21

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

mainc prog

int a = 1 ) prog

gcc -o prog mainc 13

mainc

int a = 1 prog

) prog main2c

int b = 2

gcc -o prog mainc main2c 14

$ gcc -o prog mainc $ prog Hello World $

15

DONE $ gcc -o prog mainc $ prog Hello World $

16

ldquoTo debug the sausage one must see how it is maderdquo

mdashSomeone probably

17

Mainjava Mainclass

( int a = 1 java Main

18

Mainjava Mainclass

(

mainpyc

(

a = 1

mainpy

int a = 1 java Main

python mainpy

19

Mainjava Mainclass

int a = 1 (

maino

)

prog

(

mainpyc

(

int a = 1

mainc

a = 1

mainpy

int a = 1 java Main

python mainpy

prog

20

21

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

mainc

int a = 1 prog

) prog main2c

int b = 2

gcc -o prog mainc main2c 14

$ gcc -o prog mainc $ prog Hello World $

15

DONE $ gcc -o prog mainc $ prog Hello World $

16

ldquoTo debug the sausage one must see how it is maderdquo

mdashSomeone probably

17

Mainjava Mainclass

( int a = 1 java Main

18

Mainjava Mainclass

(

mainpyc

(

a = 1

mainpy

int a = 1 java Main

python mainpy

19

Mainjava Mainclass

int a = 1 (

maino

)

prog

(

mainpyc

(

int a = 1

mainc

a = 1

mainpy

int a = 1 java Main

python mainpy

prog

20

21

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

$ gcc -o prog mainc $ prog Hello World $

15

DONE $ gcc -o prog mainc $ prog Hello World $

16

ldquoTo debug the sausage one must see how it is maderdquo

mdashSomeone probably

17

Mainjava Mainclass

( int a = 1 java Main

18

Mainjava Mainclass

(

mainpyc

(

a = 1

mainpy

int a = 1 java Main

python mainpy

19

Mainjava Mainclass

int a = 1 (

maino

)

prog

(

mainpyc

(

int a = 1

mainc

a = 1

mainpy

int a = 1 java Main

python mainpy

prog

20

21

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

DONE $ gcc -o prog mainc $ prog Hello World $

16

ldquoTo debug the sausage one must see how it is maderdquo

mdashSomeone probably

17

Mainjava Mainclass

( int a = 1 java Main

18

Mainjava Mainclass

(

mainpyc

(

a = 1

mainpy

int a = 1 java Main

python mainpy

19

Mainjava Mainclass

int a = 1 (

maino

)

prog

(

mainpyc

(

int a = 1

mainc

a = 1

mainpy

int a = 1 java Main

python mainpy

prog

20

21

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

ldquoTo debug the sausage one must see how it is maderdquo

mdashSomeone probably

17

Mainjava Mainclass

( int a = 1 java Main

18

Mainjava Mainclass

(

mainpyc

(

a = 1

mainpy

int a = 1 java Main

python mainpy

19

Mainjava Mainclass

int a = 1 (

maino

)

prog

(

mainpyc

(

int a = 1

mainc

a = 1

mainpy

int a = 1 java Main

python mainpy

prog

20

21

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Mainjava Mainclass

( int a = 1 java Main

18

Mainjava Mainclass

(

mainpyc

(

a = 1

mainpy

int a = 1 java Main

python mainpy

19

Mainjava Mainclass

int a = 1 (

maino

)

prog

(

mainpyc

(

int a = 1

mainc

a = 1

mainpy

int a = 1 java Main

python mainpy

prog

20

21

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Mainjava Mainclass

(

mainpyc

(

a = 1

mainpy

int a = 1 java Main

python mainpy

19

Mainjava Mainclass

int a = 1 (

maino

)

prog

(

mainpyc

(

int a = 1

mainc

a = 1

mainpy

int a = 1 java Main

python mainpy

prog

20

21

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Mainjava Mainclass

int a = 1 (

maino

)

prog

(

mainpyc

(

int a = 1

mainc

a = 1

mainpy

int a = 1 java Main

python mainpy

prog

20

21

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

21

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

22

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

mainc

int a = 1 ( ) int a = 1 prog

Pre-Process

Compile

Link 23

maino prog

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

mainc

int a = 1int a = 1

Pre-Process

(

main2o

(

) prog

Compile

Link 24

progmaino

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Pre-Process

Compile

Link

25

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Pre-Process

Compile

Link

26

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

include

define

ifdef 27

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

rimshottxt

ba-dum chh

joketxt

A man walks into a bar Ouch include rimshottxt

cpp -P joketxt 28

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

output

A man walks into a bar Ouch ba-dum chh

cpp -P joketxt 29

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

doublepy

define fosho def define kthx return define wutz print

fosho double(x) kthx x 2

wutz double(6)

These are called ldquomacrosrdquo

cpp -P doublepy 30

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

output

def double(x) return x 2

print double(6)

cpp -P doublepy 31

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

AWESOME

output

def double(x) return x 2

print double(6)

cpp -P doublepy | python

12

cpp -P doublepy 32

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 33

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

beertxt

define beer(x) x bottles of beer on the wall

beer(99) beer(98) beer(97)

cpp -P beertxt 34

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

output

99 bottles of beer on the wall 98 bottles of beer on the wall 97 bottles of beer on the wall

cpp -P beertxt 35

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

answertxt

Whatrsquos 7 times 6 ifdef REVEAL 42 endif

cpp -P answertxt 36

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

output

Whatrsquos 7 times 6

cpp -P answertxt 37

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

output

Whatrsquos 7 times 6

cpp -P answertxt 38

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

define REVEAL

cpp -P answertxt 39

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

define REVEAL

or

cpp -P -D REVEAL answertxt

cpp -P answertxt 40

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

output

Whatrsquos 7 times 6 42

cpp -P -D REVEAL answertxt 41

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

answertxt

Whatrsquos 7 times 6 ifndef REVEAL 42 endif

cpp -P answertxt 42

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

(Fancy) String Substitution

43

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

How is this used in C

44

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

helloc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 45

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 46

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

helloc angle brackets -gt use the system search path

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -E helloc 47

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

output

int printf(const char ) __attribute__((__format__ (__printf__ 1 2)))

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 48

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

output

int printf(const char )

int main() printf(Hello Worldn)

pretending printf is all thatrsquos defined in stdioh

gcc -E helloc 49

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

include is not import pickle

import javaio

50

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

fibc

define MAX_FIB 20 int fib[MAX_FIB]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt MAX_FIB i++)

fib[i] = fib[i-1] + fib[i-2] return 0

gcc -E fibc 51

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

output

int fib[20]

int main() fib[0] = 0 fib[1] = 1 for(int i = 2 i lt 20 i++)

fib[i] = fib[i-1] + fib[i-2]

gcc -E fibc 52

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

debugc

include ltstdiohgt

int main() ifdef DEBUG

printf(Hello Worldn) endif

return 0

gcc -DDEBUG debugc -o debug 53

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

debugc

include ltstdiohgt

int main() printf(Hello Worldn) return 0

gcc -DDEBUG debugc -o debug 54

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

debugc

include ltstdiohgt

int main() return 0

gcc debugc -o debug 55

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Pre-Process

Compile

Link

56

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

int a = 1 (

maino

)

prog

int a = 1

mainc

prog

57

Compile

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Compile

Type-checking Linear processing

58

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Type-checking int reptile()

return frog

59

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Type-checking int reptile()

return frog

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

60

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

61

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Type-checking def vegetable(day)

if day = Tuesday return tomato

else return 1000

Python says no problem 62

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

int reptile() return frog

63

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

int () return char

64

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

int vegetable(char day) if (strcmp(day Tuesday) = 0)

return tomato else

return 1000

65

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

int (char) if (int)

return char else

return int

66

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

int (char) if (int)

return char else

return int

67

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

int (char) if (int) return char else return int

68

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Everything has a single fixed type

69

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

def foo(a b) return a + b

foo(2 3) foo(2 3)

70

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Variable Declarations int foo float foo double foo char foo

int foo[42] int foo struct Bar foo

71

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Function Declarations double fmin(double double)

return type argument types

72

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Function Declarations void exit(int)

returns nothing

int rand(void)

takes no arguments 73

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

int foo(int a int b) return a + b

74

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

75

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

reptilec In function lsquoreptilersquo reptilec25 warning return makes integer from pointer without a cast

int a = 4 float b = (float)a

76

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

all theoretical casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

77

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

78

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

79

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

allowed casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 80

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

allowed casts

int float double char int[] int void (f )(int) struct X

int float double char int[] int void (f )(int) struct X

81

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) void (f )(int) struct X struct X

82

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

implicit casts

int float double char int[] int void (f )(int)

int float double char int[] int void (f )(int)

struct X struct X 83

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

implicit casts

int int float float double double char char int[] int

int[] int

void (f )(int) void (f )(int) struct X struct X

84

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

implicit casts

int int float float double double char char int[] int[] int int void (f )(int) struct X

void (f )(int) struct X

85

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Compile

Type-checking Linear processing

86

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Linear processing ( just a small note)87

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

You can only use whatrsquos declared above

88

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

int main() printf(dn answer()) return 0

int answer() return 1337

89

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

int main() printf(dn answer()) return 0

int answer() return 1337

90

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

int answer() return 1337

int main() printf(dn answer()) return 0

91

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

92

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

HMM 93

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

int answer() declaration

int main() printf(dn answer()) return 0

int answer() definition return 1337

94

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

int answer()

int main() printf(dn answer()) return 0

declaration

int answer() return 1337

definition

95

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

int answer() declaration

include answerh

int main() printf(dn answer()) return 0

int answer() return 1337

definition

96

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Pre-Process

Compile

Link

97

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

maino

int main()

int answer()

98

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

maino

int main()

99

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

100

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

101

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

102

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

103

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols for architecture x86_64

_answer referenced from _main in ccuzmRrmo

ld symbol(s) not found for architecture x86_64collect2 ld returned 1 exit status

Linker ldquoI looked in all the object files but I couldnrsquot find answerrdquo

104

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

maino

int main()

105

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

maino answero

int main()

int answer()

106

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

maino answero

int main()

int answer()

int main() printf(dn answer()) return 0

int answer() return 1337

107

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

maino answero

int main()

int answer()

108

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

prog

gcc -o prog mainc answerc

int main()

int answer()

109

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

110

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo

Compiler ldquoI donrsquot know what answer is Irsquoll assume it returns an intrdquo

111

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

answerh

int answer()

include answerh

int main()

mainc

printf(dn answer()) return 0

112

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

answerh

int answer()

answerc

include answerh

int answer() return 1337

113

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Summary 114

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

answerh

int answer()

mainc

include answerh

int main() printf(dn answer()) return 0

115

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Preprocess gcc -E mainc

int answer()

int main() printf(dn answer()) return 0

116

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Compile gcc -c mainc mainc

maino

(

answero

(

117

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Link gcc -o prog maino maino

prog

(

118

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

Pre-Process

Compile

Link

119

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

MIT OpenCourseWarehttpocwmitedu

6S096 Introduction to C and C++IAP 2013

For information about citing these materials or our Terms of Use visit httpocwmiteduterms

top related