A quick question about declaring parent structs (structs with structs inside them):
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
*
*/
struct basic_struct {
int day;
int month;
int year;
char date [12];
};
struct gsm_struct {
char Callcomm[15];
char Textcomm[15];
char Hangupcomm[15];
};
struct dynamic_struct {
struct basic_struct inner_struct;
struct gsm_struct gsm;
};
int main(int argc, char** argv) {
return (EXIT_SUCCESS);
}
In the above code, should I initialize instances of dynamic_struct at the end of the struct declaration? like so:
Code:
struct dynamic_struct {
struct basic_struct inner_struct;
struct gsm_struct gsm;
} gsm, banana, example;
More to my question, if I initialized and instance in the main loop, would it create structs within structs infinitely? I have read it is also best practice to declare a pointer to the infant struct within the parent struct, in order to avoid the same problem. like so:
Code:
struct dynamic_struct {
struct basic_struct *inner_struct;
struct gsm_struct *gsm;
};
That way you can initialize inside the main loop without infinite overflows. Is this true?
Thanks in advance
MedicineMan25