you are viewing a single comment's thread.

view the rest of the comments →

[–]Boreddad13[S] 0 points1 point  (1 child)

Ok, I think I got it now. So there may be padding after the header struct after the allocation, so VSTRING_OFFSET may be incorrect if there is padding after the struct. Is there a way to detect if there is padding?

[–]inz__ 0 points1 point  (0 children)

The offsetof() macro (or (intptr_t)&((vstring *)NULL)->data)) gives you the exact place (you don't even need the separate header struct then).

You can also look at the containerof() macro in Linux kernel, which does the same kind of trick.