Skip to content

Instantly share code, notes, and snippets.

View pkutaj's full-sized avatar

pavol kutaj pkutaj

View GitHub Profile
@pkutaj
pkutaj / tmp9f10fchk.c
Created April 20, 2026 07:20
CTJ-46: The Stack snippet
#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()
@pkutaj
pkutaj / tmpyy8ga8ao.txt
Created April 20, 2026 07:20
CTJ-46: The Stack snippet
[cling]$ my_func()
code address of my_func: 0x109cd0000
stack address of local_var: 0x16b625f9c
@pkutaj
pkutaj / tmpzq0dvax_.txt
Created April 20, 2026 07:20
CTJ-46: The Stack snippet
High addresses
┌──────────────┐
│ Stack │ ← &local_var lives here (grows ↓)
├──────────────┤
│ (unused) │
├──────────────┤
│ Heap │ ← malloc'd memory (grows ↑)
├──────────────┤
│ .bss │ ← uninitialized globals
├──────────────┤
@pkutaj
pkutaj / tmp8kskm44z.c
Created April 9, 2026 07:42
CTJ42_Union snippet
typedef union AgeOrName {
int age;
const char *name;
} age_or_name_t;
@pkutaj
pkutaj / tmphygjpo33.c
Created April 9, 2026 07:42
CTJ42_Union snippet
#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)
@pkutaj
pkutaj / tmpaon9ux5j.c
Created April 9, 2026 07:42
CTJ42_Union snippet
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);
@pkutaj
pkutaj / tmp8re_cqci.txt
Created April 9, 2026 07:42
CTJ42_Union snippet
[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
@pkutaj
pkutaj / tmpjtec0_pd.c
Created April 9, 2026 07:42
CTJ42_Union snippet
#include <stdio.h>
age_or_name_t pavol = { .age = 42 };
printf("age: %d\n", pavol.age);
@pkutaj
pkutaj / tmp44f5uif3.c
Created April 9, 2026 07:42
CTJ42_Union snippet
printf("name: %s\n", pavol.name);
@pkutaj
pkutaj / tmppq52ejek.txt
Created April 9, 2026 07:42
CTJ42_Union snippet
❯ 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);