Browse Source

first commit

master
zapashcanon 4 months ago
commit
26f583ec5e
Signed by: zapashcanon GPG Key ID: 8981C3C62D1D28F1
  1. 1
      .gitignore
  2. 1
      README.md
  3. 3
      dune-project
  4. 55
      src/README.md
  5. 1
      src/dune
  6. 27
      src/memory_layout.c

1
.gitignore

@ -0,0 +1 @@
_build

1
README.md

@ -0,0 +1 @@
# Garbage

3
dune-project

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

55
src/README.md

@ -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

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

27
src/memory_layout.c

@ -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);
}
Loading…
Cancel
Save