![Page 1: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/1.jpg)
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
![Page 2: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/2.jpg)
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
![Page 3: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/3.jpg)
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
![Page 4: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/4.jpg)
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
![Page 5: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/5.jpg)
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
![Page 6: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/6.jpg)
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
![Page 7: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/7.jpg)
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
![Page 8: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/8.jpg)
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
![Page 9: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/9.jpg)
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
![Page 10: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/10.jpg)
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
![Page 11: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/11.jpg)
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
![Page 12: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/12.jpg)
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
![Page 13: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/13.jpg)
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
![Page 14: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/14.jpg)
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
![Page 15: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/15.jpg)
$ 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
![Page 16: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/16.jpg)
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
![Page 17: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/17.jpg)
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
![Page 18: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/18.jpg)
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
![Page 19: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/19.jpg)
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
![Page 20: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/20.jpg)
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
![Page 21: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/21.jpg)
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
![Page 22: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/22.jpg)
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
![Page 23: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/23.jpg)
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
![Page 24: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/24.jpg)
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
![Page 25: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/25.jpg)
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
![Page 26: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/26.jpg)
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
![Page 27: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/27.jpg)
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
![Page 28: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/28.jpg)
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
![Page 29: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/29.jpg)
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
![Page 30: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/30.jpg)
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
![Page 31: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/31.jpg)
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
![Page 32: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/32.jpg)
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
![Page 33: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/33.jpg)
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
![Page 34: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/34.jpg)
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
![Page 35: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/35.jpg)
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
![Page 36: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/36.jpg)
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
![Page 37: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/37.jpg)
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
![Page 38: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/38.jpg)
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
![Page 39: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/39.jpg)
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
![Page 40: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/40.jpg)
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
![Page 41: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/41.jpg)
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
![Page 42: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/42.jpg)
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
![Page 43: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/43.jpg)
(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
![Page 44: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/44.jpg)
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
![Page 45: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/45.jpg)
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
![Page 46: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/46.jpg)
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
![Page 47: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/47.jpg)
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
![Page 48: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/48.jpg)
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
![Page 49: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/49.jpg)
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
![Page 50: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/50.jpg)
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
![Page 51: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/51.jpg)
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
![Page 52: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/52.jpg)
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
![Page 53: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/53.jpg)
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
![Page 54: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/54.jpg)
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
![Page 55: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/55.jpg)
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
![Page 56: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/56.jpg)
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
![Page 57: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/57.jpg)
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
![Page 58: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/58.jpg)
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
![Page 59: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/59.jpg)
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
![Page 60: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/60.jpg)
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
![Page 61: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/61.jpg)
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
![Page 62: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/62.jpg)
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
![Page 63: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/63.jpg)
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
![Page 64: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/64.jpg)
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
![Page 65: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/65.jpg)
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
![Page 66: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/66.jpg)
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
![Page 67: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/67.jpg)
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
![Page 68: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/68.jpg)
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
![Page 69: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/69.jpg)
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
![Page 70: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/70.jpg)
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
![Page 71: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/71.jpg)
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
![Page 72: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/72.jpg)
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
![Page 73: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/73.jpg)
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
![Page 74: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/74.jpg)
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
![Page 75: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/75.jpg)
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
![Page 76: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/76.jpg)
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
![Page 77: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/77.jpg)
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
![Page 78: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/78.jpg)
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
![Page 79: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/79.jpg)
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
![Page 80: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/80.jpg)
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
![Page 81: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/81.jpg)
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
![Page 82: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/82.jpg)
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
![Page 83: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/83.jpg)
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
![Page 84: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/84.jpg)
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
![Page 85: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/85.jpg)
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
![Page 86: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/86.jpg)
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
![Page 87: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/87.jpg)
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
![Page 88: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/88.jpg)
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
![Page 89: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/89.jpg)
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
![Page 90: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/90.jpg)
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
![Page 91: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/91.jpg)
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
![Page 92: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/92.jpg)
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
![Page 93: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/93.jpg)
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
![Page 94: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/94.jpg)
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
![Page 95: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/95.jpg)
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
![Page 96: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/96.jpg)
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
![Page 97: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/97.jpg)
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
![Page 98: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/98.jpg)
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
![Page 99: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/99.jpg)
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
![Page 100: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/100.jpg)
answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols 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
![Page 101: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/101.jpg)
answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols 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
![Page 102: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/102.jpg)
answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols 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
![Page 103: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/103.jpg)
answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols 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
![Page 104: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/104.jpg)
answerc In function lsquomainrsquo answerc4 warning implicit declaration offunction lsquoanswerrsquo Undefined symbols 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
![Page 105: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/105.jpg)
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
![Page 106: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/106.jpg)
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
![Page 107: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/107.jpg)
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
![Page 108: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/108.jpg)
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
![Page 109: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/109.jpg)
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
![Page 110: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/110.jpg)
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
![Page 111: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/111.jpg)
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
![Page 112: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/112.jpg)
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
![Page 113: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/113.jpg)
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
![Page 114: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/114.jpg)
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
![Page 115: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/115.jpg)
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
![Page 116: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/116.jpg)
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
![Page 117: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/117.jpg)
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
![Page 118: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/118.jpg)
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
![Page 119: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/119.jpg)
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
![Page 120: 6.S096 Lecture 1: Compilation Pipelineopen.gnu.ac.kr/.../Slides_c/MIT6_S096_IAP13_lec1.pdf · 2017. 9. 4. · “To debug the sausage, one must see how it is made.” —Someone,](https://reader034.vdocument.in/reader034/viewer/2022051914/6005ea8e68f18048cd7d7c74/html5/thumbnails/120.jpg)
MIT OpenCourseWarehttpocwmitedu
6S096 Introduction to C and C++IAP 2013
For information about citing these materials or our Terms of Use visit httpocwmiteduterms