How to: Is the "struct hack" technically undefined behavior? #computers #fix #dev
How to: Is the "struct hack" technically undefined behavior? #computers #fix #dev
Is the "struct hack" technically undefined behavior?
What I am asking about is the well known “last member of a struct has variable length” trick. It goes something like this:
struct T { int len; char s[1]; }; struct T *p = malloc(sizeof(struct T) + 100); p->len = 100; strcpy(p->s, "hello world");
Because of the way that the struct is laid out in memory, we are able to overlay the struct over a…
View On WordPress








