Here's the scenario.
I have some structures...
Code:
struct entry {
char name[8] ;
int age ;
} ;
struct entry Table1[] = { // An array of entry's.
"Dino" , 1 ,
"Bambam" , 2 ,
"Pebbles", 3
} ;
struct section {
struct entry * an_entry ;
int length ;
char data[8] ;
}
// I'm struggling with the structure below...
struct section Table2[] = { // An array of sections
& first entry in Table1 , 5, "abc" ,
& second entry in Table1 , 5, "def" ,
& third entry in Table1 , 2, "9999"
} ;
Conceptually, I would like to be able to assign a label to each entry of Table1 so that Table2 section.an_entry points to the Table1 entry I want. It's a constant table and does not change at runtime.
This, obviously isn't legal syntax, but it would look like this
Code:
struct entry Table1[] = { // An array of entry's.
e1: "Dino" , 1 ,
e2: "Bambam" , 2 ,
e3: "Pebbles", 3
} ;
struct section Table2[] = { // An array of sections
&e1 , 5, "abc" ,
&e2 , 5, "def" ,
&e3 , 2, "9999"
} ;
Is there a way to do this? I haven't tried to see if it's legal, but if it is, I would rather not code
Code:
struct section Table2[] = { // An array of sections
&Table1[0] , 5, "abc" ,
&Table2[1] , 5, "def" ,
&Table1[2] , 2, "9999"
} ;
because Table1 might change in the future, and it might have 50 elements in it. I would prefer a symbolic label or address instead of hardcoding an array subscript (again, if it's even legal).