Randall Parker
2008-06-13 15:58:49 UTC
We've got a struct:
struct msgStruct {
unsigned int msgSize; // the number of bytes in the response.
unsigned char *pMsg;
};
Then we do things like:
struct msgStruct Msg1 = {6,"Hello"};
struct msgStruct Msg2 = {9,"Good bye"};
and Msg3, 4, etc..
Then we want to do:
struct msgStruct MsgArray[] = {
Msg1,
Msg2,
etc.....
};
Well, CG CB 2007 objects to this syntax which gcc and MS VS 2003 happily accept. CG's compiler expects to see
unsigned int,
unsigned char *,
unsigned int,
unsigned char *,
unsigned int,
unsigned char *,
So I figured the problem was with the outer squiggly brackets. So I tried this:
struct msgStruct MsgArray[] =
Msg1,
Msg2,
etc.....
;
Then it complained about how a { was expected.
How can I do this? I do not want to put all the int and char* values in the initialization of the array. First off, a large amount of code does it this other way with struct vars first declared. Second, we reuse the same message in different arrays. I do not want duplicates with the possibility of inconsistencies.
struct msgStruct {
unsigned int msgSize; // the number of bytes in the response.
unsigned char *pMsg;
};
Then we do things like:
struct msgStruct Msg1 = {6,"Hello"};
struct msgStruct Msg2 = {9,"Good bye"};
and Msg3, 4, etc..
Then we want to do:
struct msgStruct MsgArray[] = {
Msg1,
Msg2,
etc.....
};
Well, CG CB 2007 objects to this syntax which gcc and MS VS 2003 happily accept. CG's compiler expects to see
unsigned int,
unsigned char *,
unsigned int,
unsigned char *,
unsigned int,
unsigned char *,
So I figured the problem was with the outer squiggly brackets. So I tried this:
struct msgStruct MsgArray[] =
Msg1,
Msg2,
etc.....
;
Then it complained about how a { was expected.
How can I do this? I do not want to put all the int and char* values in the initialization of the array. First off, a large amount of code does it this other way with struct vars first declared. Second, we reuse the same message in different arrays. I do not want duplicates with the possibility of inconsistencies.