1. előadás
Meta
Kezdés: 12:15 Porkoláb Zoltán gsd@inf.elte.hu
Cél: feladatok részekre bontása, amíg nem triviális/már létező
Történelem
Programozási pragmatika: Hogyan lehet részekre bontani a programokat
Régen: hardware-hez kellett írni a programokat, gépikódban
-
Assembly: gépikód szöveges leírása. Egy-az-egyben megfelel neki, de olvashatóbb
-
Fortran: gépikód független programozási nyelv. Cél: kb. 10 fortran utasítás == 9 Assembly utasítás
Gyorsabb gépek, kevésbé cél a sebesség. Drágább lett a programozó, mint a számítógép: szükséges használhatóbb programozási nyelv.
C nyelv: Gyorsabb, kevésbé erőforrásigényes, kevesebb áramot igényel (mars rover go brr)
Timeline
-
1969-1973: Bell Labs, C
-
1988 – ANSI C
-
1989 – ANSI C standard (C90) (Ezt fogjuk használni)
-
1999 – C99
-
2011 – C11
Compiler VS Interpreter
-
Interpreter - Futtatási időben dolgozza fel a programot. Nem tud előre hibákat elfogni, nem tud optimalizálni.
-
Fordító (Compiler) - Előre feldolgozza a programot, lefordítja gépkódjra. Hatékony végrehatjás. Lehetséges az optimalizálás, ellenőrzés. A fordítást egy adott hardware-re teszi.
#include <stdio.h> //include standard I/O library
int main() { // function main returns an int, takes no arguments
printf("Hello, World!\n");
return 0; // return an "OK" code, return 1 here when error
}
Compilation steps
-
Preprocessing (include stdio, basically paste the whole thing in)
-
gcc -S helloworld.c--> generates Assembly code (helloworld.s) -
gcc -c helloworld.s--> generates object code (helloworld.o) This is already machine code, but not executable platform-specific, but it doesn't include stdio and all other libraries -
gcc helloworld.o -o helloworld--> generates executable (helloworld) (Linker step, add all the libraries together, package all the different files together, produce the final executable)
gcc helloworld.c --> all in one step
Linking types
Dynamic linker: when you run the executable, it loads the libraries into memory, not included in the executable
E.g. .dll or .so files
Static linker: all the libraries are included in the executable
Proper compilation
Enables all compiler warnings (recommended)
C generally compiles pretty much everything, but having warnings is real bad :)