C
copx
What is wrong with the following code? My compiler (GCC) produces a warning
which states that the initialisation values of a local struct are "not
computable at load time". A warning is not equal to an error, but it usually
suggests that the code is at least questionable. I do not see anything
questionable...
This program demonstrates the issue. I get the warning whenever I pass a
pointer to a structure and use the fields of that structure to initalise the
values of a local structure. What is not kosher about that?
===
typedef struct {
int *ab;
int *ac;
} TEST;
typedef struct {
int *b;
int *c;
} TESTO;
void testo(TEST *aba)
{
/* warning - not computable at load time? */
TESTO kd = {aba->ab, aba->ac};
}
int main(void)
{
TEST aba;
testo(&aba);
return 0;
}
OK, the fields of aba are not initalised in this demo code, but that does
not matter. The warning shows up even if all fields of the passed structure
contain valid values.
which states that the initialisation values of a local struct are "not
computable at load time". A warning is not equal to an error, but it usually
suggests that the code is at least questionable. I do not see anything
questionable...
This program demonstrates the issue. I get the warning whenever I pass a
pointer to a structure and use the fields of that structure to initalise the
values of a local structure. What is not kosher about that?
===
typedef struct {
int *ab;
int *ac;
} TEST;
typedef struct {
int *b;
int *c;
} TESTO;
void testo(TEST *aba)
{
/* warning - not computable at load time? */
TESTO kd = {aba->ab, aba->ac};
}
int main(void)
{
TEST aba;
testo(&aba);
return 0;
}
OK, the fields of aba are not initalised in this demo code, but that does
not matter. The warning shows up even if all fields of the passed structure
contain valid values.