Separate Compilation
Separate Compilation
A key concept in programmingTwokinds oflanguages,compilation(C,Pascal,...)and interpretation(Lisp,Matlab,Phython,Javascript...)Itwasamilestone forproceduralprogramming,someoldoneslikePascalcannot,..It is in fact a kindof'abstract datatype,to separate the function"implementations”fromits“definitionsIt is alsoimpossibleforlargeprojetwithout it
A key concept in programming ▪ Two kinds of languages, compilation (C, Pascal, .) and interpretation (Lisp, ., Matlab, Phython, Javascript.) ▪ It was a ‘milestone’ for procedural programming, some old ones like Pascal cannot, . ▪ It is in fact a kind of ‘abstract data type’, to separate the function “implementations” from its “definitions” ▪ It is also impossible for large projet without it
Translating a LibraryProgramProgramSource FileObject FileC++Compilerg++ -cLibraryLinkerHeaderFileProgramExecutableFileC++e.g.i?Compilerg++ foo.cpp bar.o fb.oLibraryLibraryg++ -cImplementationFileObject File
Translating a Library 3 Program Source File Library Header File Library Implementation File C++ Compiler C++ Compiler Linker Program Object File Library Object File Program Executable File g++ -c g++ -c .o .o e.g., g++ foo.cpp bar.o fb.o
Motivation#include<iostream>usingnamespace stdbool even(int);bool odd(int x)boolres;if(x==0)res=false;else even(x-1);return res;booleven(intx)(boolres;if (x==0)res=true;else odd(x-1);retum res;intmainointx,cin>>x,cout>>odd(x)>>endl;cout>>even(x)>>endl;return 0;
Motivation #include <iostream> using namespace std; bool even(int); bool odd(int x) { bool res; if(x == 0) res=false; else even(x-1); return res; } bool even(int x) { bool res; if (x == 0) res=true; else odd(x-1); return res; } int main() { int x; cin >> x; cout >> odd(x) >> endl; cout >> even(x) >> endl; return 0; }
#include<iostream>using namespace std;bool even(int);It'saboutOrganization',organizationoffiles!bool odd(int);:intmainointx,cin>> x,cout>>odd(x)>>endl;cout >>even(x) >>endl;return O:boolodd(intx)boolres;if(x ==0) res=falseelse even(x-1):return res;booleven(intx)boolres;if(x==0)res=true;else odd(x-1);retun res;
#include <iostream> using namespace std; bool even(int); bool odd(int); int main() { int x; cin >> x; cout >> odd(x) >> endl; cout >> even(x) >> endl; return 0; } bool odd(int x) { bool res; if(x == 0) res=false; else even(x-1); return res; } bool even(int x) { bool res; if (x == 0) res=true; else odd(x-1); return res; } It’s about ‘Organization’, organization of files!