digitalmars.D.learn - static array of structures
- Ben Gardner (23/23) Mar 31 2006 Hi,
- kris (8/38) Mar 31 2006 it needs to have square brackets for the array assignment:
- Ben Gardner (2/12) Mar 31 2006
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
Mar 31 2006
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! Benit 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 }, ];
Mar 31 2006
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 }, ];
Mar 31 2006