I came across this code:
typedef struct {
char *name;
char *value;
} SPAM;
typedef struct {
char *name;
int num_spams;
SPAM *spams;
} EGG;
SPAM my_spams[2] = {
{ "name1", "value1" },
{ "name2", "value2" },
};
EGG my_eggs[1] = {
{ "first egg", 1, my_spams }
};
EXPORT(int) getSPAMANDEGGS(EGG **eggs)
{
*eggs = my_eggs;
return 1;
}
In this declaration shouldn't the definition of EGG struct have SPAM **spams; as the definition of the spams member since we store an array of SPAMs there later?
SPAM *spamscan point to the first element of an array ofSPAM.char foo[] = "abc"; char *foo_ptr = foo;{ "first egg", 1, my_spams }should be{ "first egg", 2, my_spams }, becausenum_spamsshould correspond to the number of elements inmy_spamsarray, which is 2.