P
pozzugno
#define NUM_JHON 1
#define NUM_RICHARD 2
#define NUM_ERIC 3
#define MYLIST NUM_JHON, RICHARD, ERIC
int addressbook[] = { MYLIST };
In the above code, I can change MYLIST #define and
automatically I'll have a correcly sized addressbook[]
array.
Now I want to declare 3 addressbooks:
#define MYLIST1 NUM_JHON, RICHARD, ERIC
#define MYLIST2 NUM_JHON, RICHARD, ERIC
#define MYLIST3 NUM_JHON, RICHARD, ERIC
int addressbook[][] = { { MYLIST1 }, { MYLIST2 }, { MYLIST3 } };
The compiler gives me an error. It seems the second index
must be defined and the first will be automatically calculated
based on the initialization.
Why the second can't be calculated at compile-time as the
first index? I understand MYLST1, MYLST2 and MYLIST3 could be
of different lengths, but the compiler could assume the maximum.
#define NUM_RICHARD 2
#define NUM_ERIC 3
#define MYLIST NUM_JHON, RICHARD, ERIC
int addressbook[] = { MYLIST };
In the above code, I can change MYLIST #define and
automatically I'll have a correcly sized addressbook[]
array.
Now I want to declare 3 addressbooks:
#define MYLIST1 NUM_JHON, RICHARD, ERIC
#define MYLIST2 NUM_JHON, RICHARD, ERIC
#define MYLIST3 NUM_JHON, RICHARD, ERIC
int addressbook[][] = { { MYLIST1 }, { MYLIST2 }, { MYLIST3 } };
The compiler gives me an error. It seems the second index
must be defined and the first will be automatically calculated
based on the initialization.
Why the second can't be calculated at compile-time as the
first index? I understand MYLST1, MYLST2 and MYLIST3 could be
of different lengths, but the compiler could assume the maximum.