Is it possible to compute at compile time the size of a padding array required in a structure such that the structure ends up being a per-determined size. That is I would like to do something like this (which I know won't work)
#define APPDESCTARGETSIZE 256 // Target size for the App Desc Structure
// Structure member size of
#define msizeof(type, member) sizeof(((type *)0)->member)
// Size of padding arrary
#define padsize (APPDESCTARGETSIZE - (offsetof(custom_app_desc_t, pad) + msizeof(custom_app_desc_t, tail)))
/** * @brief Description about application. */
typedef struct {
uint8_t header[16];
char progname[16];
char boardname[16];
uint8_t chipsize;
uint8_t version_maj;
uint8_t version_min;
uint8_t version_iss;
uint8_t pad[padsize];
uint8_t tail[16];
} custom_app_desc_t;
I can solve with a manual calculation such as below but it would nice for the compiler to do math for me:
#define padsize (APPDESCTARGETSIZE - 68)
NOTE, it is important in this case that pad occurs before the 'tail' member.