Let's say I declare a fixed size array and initialize it's members. Is there a way to check at compile time, if all members were initialized, so that I can avoid bugs because of unitialized values? Here's an example I'm working on:
enum image_format {
IMAGE_FORMAT_UBI = 0,
IMAGE_FORMAT_BOOT,
IMAGE_FORMAT_RAW,
_IMAGE_FORMAT_LAST
};
#define IMAGE_FORMAT_COUNT (_IMAGE_FORMAT_LAST - IMAGE_FORMAT_UBI)
static int image_format_validator_ubi(const char *filename);
static int image_format_validator_boot(const char *filename);
typedef int (*image_format_validator)(const char *filename);
static image_format_validator image_format_validators[IMAGE_FORMAT_COUNT] = {
[IMAGE_FORMAT_UBI] = &image_format_validator_ubi,
[IMAGE_FORMAT_BOOT] = &image_format_validator_boot,
[IMAGE_FORMAT_RAW] = NULL
};
In this case, I'd like to check that IMAGE_FORMAT_COUNT
amount of elements were initialized inside the image_format_validators
array.