I’ve got this code, which I don’t understand why it doesn’t compile:
typedef struct
{
uint32_t serial_number;
uint32_t ieee_address[6];
} FACTORY_CONFIG;
...
// Unlock flash (only the portion we write on)
error = FLASHD_Unlock ( writeaddress, writeaddress + sizeof ( FACTORY_CONFIG.serial_number ), 0, 0 );
When I run it, I get this error:
Error[Pe018]: expected a “)”
When I change the
FACTORY_CONFIG.serial_number
to
FACTORY_CONFIG
, it compiles and everything works. I’m not sure, can I check the size of a type inside a structure ?
You can’t just access members of types in C like that. You can, however, take
sizeoffrom actual objects. And sincesizeofis a compile-time construct, these objects don’t even have to be valid. So the following will work:If you use this a lot, or just for readability, you could make a macro out of it.