Hoofdstuk 1: Introductie
1 C in a Nutshell
• Statically typed general-purpose programming language
o Statically typed = you have to specify the data types
• Preprocessor, Compiler and Linker
o Not interpreted
• “Small” language
o thin layer of abstraction
o few keywords
o low runtime overhead
• C lacks
o run-time type safety
o exceptions
o range-checking
o garbage collection
o object-oriented programming
2 C is old so why should I care...
• Lingua franca of systems programming:
o OSs, like UNIX, Linux
o embedded processors (phones, portable electronics, ...)
o microcontrollers (cars, airplanes, ...)
▪ DSP processors (digital audio and TV systems)
o Often used as an intermediate language by implementations of other languages
▪ e.g. Python (CPython), Perl 5, PHP, Pico,…
3 Scheme vs. C
Scheme C
#include <stdio.h>
int main(void){
int x = 5;
printf(“Hello World\n");
printf(“%i”, x);
return0;
}
• main = entry point of a C program
• int voor de main → geeft int terug
• (void) na de functie → waar de parameters staan, nu void want neemt geen parameters
1
, 4 Compilatie
Oproepen compiler
Programma uitvoeren
• Compiler: compileert de code van 1 file tot object file
• Linker neemt verschillende object files van programma en headers en linkt deze samen met
eventueel verschillende libraries.
2