Ethereal-dev: Re: [ethereal-dev] Complex initializers

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Gilbert Ramirez <gram@xxxxxxxxxx>
Date: Fri, 10 Dec 1999 01:28:37 -0600
On Fri, Dec 10, 1999 at 03:15:09AM +1000, Richard Sharpe wrote:
> Hi,
> 
> I am seeking to do the following:
> 
> struct something {
> 
>   char *n1;
>   char *n2;
>   char *list[];
> };
> 
> struct something st[] = {
>   { "a1", "a2", {"a3", "a4", "a5", NULL}};
> 
> with lots of initializers like the above, where the list element can have
> any number of things in it.
> 
> However, gcc won't let me do it.  Since I want to initialize lots of
> structure like that, is there any way I can do it?

I never found a way. In packet-ncp.c, I'm doing the table-driven
thing as well, with "contained" variable-sized lists of structs,
like your "contained" variable-sized list of char*'s.

I broke apart the variable-sized stuff out, and gave it its
own symbol:

/* Service Queue Job REQUEST */
static svc_record ncp_17_7C_C[] = {
                { nbelong,      4,      "The queue the job resides in" },
                { nbeshort,     2,      "Job Type" },
                { nend,         0,      NULL }
};
/* Service Queue Job REPLY */
static svc_record ncp_17_7C_R[] = {
                { nbelong,      4,      "Client station number: %d" },
                { nbelong,      4,      "Task Number: %d" },
                { nbelong,      4,      "User: %d" },
                { nbelong,      4,      "Server specifed to service queue entry: %08X" },
                { ndatetime,    6,      "Earliest time to execute" },
                { ndatetime,    6,      "When job entered queue" },
                { nbelong,      4,      "Job Number" },
                { nbeshort,     2,      "Job Type" },
                { nbeshort,     2,      "Job Position" },
                { nbeshort,     2,      "Current status of job: 0x%02x" },
                { nasciiz,      14,     "Name of file" },
                { nbelong,      4,      "File handle" },
                { nbelong,      4,      "Client station number" },
                { nbelong,      4,      "Task number" },
                { nbelong,      4,      "Job server" },
                { nend,         0,      NULL }
};

Then I use the symbols in my struct initializer:

{ 0x17, 0x7C, SUBFUNC, "Service Queue Job",
        ncp_17_7C_C, ncp_17_7C_R, NCP_QUEUE_SERVICES
},

If there is a way to get an ANSI C compiler to initialize variable-sized
lists of things inside a struct, I'd love to hear about it.

--gilbert