alchemista
Programmer
Hello, I'm trying to declare some global variables that are structures. However, some of them have nested structures and the compiler complains that the initializer is not a constant type. I thought this may be because the compiler may pad a structure, however it should be able to know this when compiling. Also, I tried using the -fpack-struct option of gcc and still I get the same error. Here's a sample of what I'm trying to do:
typedef struct {
float a;
float b;
} struct1_t;
static struct1_t NULL_STRUCT = {0.0, 0.0};
typedef struct {
float a;
struct1_t b;
} struct2_t;
static struct2_t NULL_STRUCT2 = {0.0, NULL_STRUCT};
However, this will not work. I get initializer not constant on trying to initialize the NULL_STRUCT2. How can I do such a thing in C? I'm using the gcc compiler btw.
Thanks!
typedef struct {
float a;
float b;
} struct1_t;
static struct1_t NULL_STRUCT = {0.0, 0.0};
typedef struct {
float a;
struct1_t b;
} struct2_t;
static struct2_t NULL_STRUCT2 = {0.0, NULL_STRUCT};
However, this will not work. I get initializer not constant on trying to initialize the NULL_STRUCT2. How can I do such a thing in C? I'm using the gcc compiler btw.
Thanks!