first commit

This commit is contained in:
zapashcanon 2022-03-14 23:21:55 +01:00
commit 26f583ec5e
Signed by: zapashcanon
GPG Key ID: 8981C3C62D1D28F1
6 changed files with 88 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
_build

1
README.md Normal file
View File

@ -0,0 +1 @@
# Garbage

3
dune-project Normal file
View File

@ -0,0 +1,3 @@
(lang dune 3.0)
(using mdx 0.2)

55
src/README.md Normal file
View File

@ -0,0 +1,55 @@
# Garbage
## Allocation mémoire
### Allocation statique
On peut allouer de la mémoire statiquement à deux endroits :
- dans le segment `.data` lors d'une initialisation explicite,
- dans le segment `.bss` lors d'une initialisation par zéro.
<!-- $MDX file=memory_layout.c -->
```c
// memory_layout.c
#include <stdio.h>
#include <stdlib.h>
const int x = 3;
int y = 5;
static int i;
char *my_str = "this should appear in .data";
int main(void) {
printf("x = %d\n", x);
printf("y = %d\n", y);
y = 10;
printf("y = %d\n", y);
printf("i = %d\n", i);
i = 42;
printf("i = %d\n", i);
exit(0);
}
```
```sh
$ gcc memory_layout.c -o memory_layout.exe
$ size ./memory_layout.exe
text data bss dec hex filename
1790 608 8 2406 966 ./memory_layout.exe
```
### MDX test
```ocaml
# 1 + 2;;
- : int = 3
```

1
src/dune Normal file
View File

@ -0,0 +1 @@
(mdx)

27
src/memory_layout.c Normal file
View File

@ -0,0 +1,27 @@
// memory_layout.c
#include <stdio.h>
#include <stdlib.h>
const int x = 3;
int y = 5;
static int i;
char *my_str = "this should appear in .data";
int main(void) {
printf("x = %d\n", x);
printf("y = %d\n", y);
y = 10;
printf("y = %d\n", y);
printf("i = %d\n", i);
i = 42;
printf("i = %d\n", i);
exit(0);
}