I have a structure that looks like this:
struct myStructure
{
int index1;
int index2;
void *buffer;
char fillData[];
};
I want to make the fillData member as big as it needs to make the structure an arbitrary size (512 bytes). I know I can calculate by hand and write that down but,to make this easily extensible in the future, I want it to scale up or down if needed automatically. Is there a way to achieve this automatic behaviour only using the preprocessor?
offsetofcannot be used, because it needs the fully definition of thestructto work: https://godbolt.org/z/brEhThhe7But you can put everything before the
fillDatainto astructand usesizeofon it:https://godbolt.org/z/zacxG1xrh
Using
sizeofon all members might not work because of padding.