Weeknotes 7: that time we all had COVID
-
Quiet week.
-
The bamboo is gone! Some gardeners dug it out in record time on Wednesday morning.
-
Everyone was sick with a nasty cold. We’re all better or at least mostly better now but it was considerably less fun than that time we all had COVID.
-
I saw this:
#include <stdio.h> #include <stddef.h> int add(int m, int n) { struct add { char a[m]; char b[n]; char c; }; return offsetof(struct add, c); } int main(void) { printf("%d\n", add(2, 3)); return 0; }
The general gist of how this works is easy to understand but I was surprised to see it still compiles and runs when modified such that
m
andn
are only known at runtime. How does that work?! I did not expect it to be possible to declare a struct with arbitrary length members at runtime. I am trying to figure it out from the disassembled code but, predictably, time is short. Maybe I’ll know next week.