This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| void my_func() { | |
| int local_var = 42; | |
| printf("code address of my_func: %p\n", (void*)my_func); | |
| printf("stack address of local_var: %p\n", (void*)&local_var); | |
| } | |
| my_func() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [cling]$ my_func() | |
| code address of my_func: 0x109cd0000 | |
| stack address of local_var: 0x16b625f9c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| High addresses | |
| ┌──────────────┐ | |
| │ Stack │ ← &local_var lives here (grows ↓) | |
| ├──────────────┤ | |
| │ (unused) │ | |
| ├──────────────┤ | |
| │ Heap │ ← malloc'd memory (grows ↑) | |
| ├──────────────┤ | |
| │ .bss │ ← uninitialized globals | |
| ├──────────────┤ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| typedef union AgeOrName { | |
| int age; | |
| const char *name; | |
| } age_or_name_t; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| typedef enum { OK = 200, NOT_FOUND = 404 } status_t; | |
| status_t s = NOT_FOUND; | |
| printf("status: %d\n", s); // 404 (C enums have no built-in way to print the label) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| typedef union lucky_value {int n; const char *s;} lucky_t; | |
| lucky_t pavol_luckies = {.n = 42}; | |
| printf("Pavol's lucky value: %s\n'", pavol_luckies.s); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [cling]$ printf("Pavol's lucky value: %s\n'", pavol_luckies.s); | |
| Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the envi | |
| ronment var `LLVM_SYMBOLIZER_PATH` to point to it): | |
| ... | |
| 0. Program arguments: /opt/homebrew/Cellar/cling/1.2_1/libexec/bin/cling | |
| Segmentation fault: 11 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| age_or_name_t pavol = { .age = 42 }; | |
| printf("age: %d\n", pavol.age); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| printf("name: %s\n", pavol.name); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ❯ cling | |
| ERROR in cling::CIFactory::createCI(): | |
| resource directory /private/tmp/cling-20251104-5233-k3pv11/cling-1.2/build/lib/clang/18 not | |
| found! | |
| ****************** CLING ****************** | |
| * Type C++ code and press enter to run it * | |
| * Type .q to exit * | |
| ******************************************* | |
| [cling]$ printf("name: %s\n", pavol.name); |