Thread overview | |||||
---|---|---|---|---|---|
|
March 31, 2006 static array of structures | ||||
---|---|---|---|---|
| ||||
Hi, I'm trying to convert some C code to D, but I ran into a little problem. The C code defines a fairly large static array of structures. At run time, the table is scanned to find a matching string. Below is how I think the array of structures should be written in d. I didn't post the C code because it is nearly identical. struct options_table { option_id id; char [] name; argtype_t type; }; options_table [] the_table = { { UO_option1, "option1", AT_NUM }, { UO_option2, "option2", AT_STRING }, { UO_option3, "option3", AT_BOOL }, }; However, this gives me the error: Error: a struct is not a valid initializer for a options_table [] I assume there is a simple way to do this. Thanks in advance for any help! Ben |
March 31, 2006 Re: static array of structures | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Gardner | Ben Gardner wrote:
> Hi,
>
> I'm trying to convert some C code to D, but I ran into a little problem.
> The C code defines a fairly large static array of structures.
> At run time, the table is scanned to find a matching string.
>
> Below is how I think the array of structures should be written in d.
> I didn't post the C code because it is nearly identical.
>
> struct options_table
> {
> option_id id;
> char [] name;
> argtype_t type;
> };
>
> options_table [] the_table =
> {
> { UO_option1, "option1", AT_NUM },
> { UO_option2, "option2", AT_STRING },
> { UO_option3, "option3", AT_BOOL },
> };
>
> However, this gives me the error:
> Error: a struct is not a valid initializer for a options_table []
>
> I assume there is a simple way to do this.
>
> Thanks in advance for any help!
> Ben
it needs to have square brackets for the array assignment:
options_table [] the_table =
[
{ UO_option1, "option1", AT_NUM },
{ UO_option2, "option2", AT_STRING },
{ UO_option3, "option3", AT_BOOL },
];
|
March 31, 2006 Re: static array of structures | ||||
---|---|---|---|---|
| ||||
Posted in reply to kris | Thanks! That was simple... =)
kris wrote:
>
> it needs to have square brackets for the array assignment:
>
> options_table [] the_table =
> [
> { UO_option1, "option1", AT_NUM },
> { UO_option2, "option2", AT_STRING },
> { UO_option3, "option3", AT_BOOL },
> ];
>
|
Copyright © 1999-2021 by the D Language Foundation