Found this answer here:
sizeof a struct member
Copied it completely into my code, but my compiler objects that I have a pointer to an incomplete class type.
uint8_t clStructCount = sizeof(((struct ALMConfStr *) 0)->IntelRecsPerPg);
What am I doing wrong? I want to set clStructCount equal to the value of IntelRecsPerPg at runtime; I thought this was the trick to do so.
Thanks!
The definition of your structure needs to be visible at the point where the compiler encounters your sizeof code.
So, this translation unit should work:
whether it’s all in one file, or the struct is in a header
#included before yoursizeofcode.However, this:
won’t work, because the compiler doesn’t know what a
struct ALMConfStrconsists of, or what anIntelRecsPerPgmight be in that context.