c - Problems with arrays of unspecified lengths -
i'm writing irda stack in c , implementing information access service component , need lookup table class/key/value pairs. keep in orderly format, i'm trying put 1 initialiser. following code works fine , compiles data compact linked tables in rom.
#define ias_ptype_string 0x00 #define ias_ptype_byte 0x01 typedef struct { ubyte* name; ubyte type; ubyte* value; } ias_attrib_t ; typedef ias_attrib_t* ias_attrib_list_t[]; typedef struct { ubyte* name; ias_attrib_list_t* attributes; } ias_class_t; static const ias_class_t ias_database[] = { {"irda:ircomm", &(ias_attrib_list_t){ &(ias_attrib_t){"parameters", ias_ptype_string, "irda:tinytp:lsapsel"}, null, }, }, }; however i'm having trouble getting data out. according types used, should able this:
ubyte class = 1; ubyte attr = 1; ubyte* name = (*(ias_database[class].attributes))[attr]->name; this because
ias_database[class].attributestypeias_attrib_list_t**(ias_database[class].attributes)typeias_attrib_list_ti.e.ias_attrib_t*[](*(ias_database[class].attributes))[attr]should typeias_attrib_t*(*(ias_database[class].attributes))[attr]->nameshould typeubyte*
however when try query table, invalid use of array unspecified bounds mspgcc. hack (ias_attrib_t*)((ias_database[class].attributes)+(sizeof(ias_attrib_t)*attr)) fails until cast db void (ias_attrib_t*)((void*)(ias_database[class].attributes)+(sizeof(ias_attrib_t)*attr)) feels dirty. i'd figure out correct syntax right way.
never mind. in utter frustration seems tried every variant bar 1 put here. (*(ias_database[class].attributes))[attr] indeed work , works when expressed (*ias_database[class].attributes)[attr] believe compiler incorrectly assuming first pointer (being ubyte**) list , trying apply index pointer type (where type incomplete).
Comments
Post a Comment