Lets assume I have a structure:
struct A {
uint16_t a;
uint64_t b;
};
is there a way to get the size of A w/o padding ? i.e.: The sum of sizeof of all the members (even if it is not recursive).
Normally sizeof(A) == 16.
I would like __GCC_sizeof__(A) == 10
.
I want it in a test code w/o affecting the actual code, which means no "#pragma"
s and no "__attribute__"
in the structure definition.
(Though it can be done with #ifdef TEST
, but it is very ugly).
It doesn't have to be portable, GCC
is enough.
Thanks!
I think sizeof(A::a) + sizeof(A::b)
should do the trick for you. There's no way to get an unpadded size of a struct because what purpose could such a size serve a program?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With