I
Ian Pilcher
I need to create a static array of structures with the following
characteristics:
* The first few members of the array are pre-initialized
* The remaining members of the array are initialized to "zero"
* The number of additional members is determined by a #defined constant,
independently of the number of pre-initialized members
Here's what I've come up with:
#define NUM_EXTRA_FOOS 5
struct foo {
int data;
};
static struct {
struct foo builtin[5];
struct foo extra[NUM_EXTRA_FOOS];
} all_foos = {
{ { 1 }, { 2 }, { 3 }, { 4 }, { 5 } },
{ { 0 } }
};
#define foos all_foos.builtin
I believe that I can effectively use foos[] as an array with 10 (5 +
NUM_EXTRA_FOOS) elements.
* Is my belief correct?
* Is there any danger of the compiler inserting unwanted padding between
the builtin and extra members of the anonymous struct?
* Is there a better way to do this?
Thanks!
characteristics:
* The first few members of the array are pre-initialized
* The remaining members of the array are initialized to "zero"
* The number of additional members is determined by a #defined constant,
independently of the number of pre-initialized members
Here's what I've come up with:
#define NUM_EXTRA_FOOS 5
struct foo {
int data;
};
static struct {
struct foo builtin[5];
struct foo extra[NUM_EXTRA_FOOS];
} all_foos = {
{ { 1 }, { 2 }, { 3 }, { 4 }, { 5 } },
{ { 0 } }
};
#define foos all_foos.builtin
I believe that I can effectively use foos[] as an array with 10 (5 +
NUM_EXTRA_FOOS) elements.
* Is my belief correct?
* Is there any danger of the compiler inserting unwanted padding between
the builtin and extra members of the anonymous struct?
* Is there a better way to do this?
Thanks!