C Preproccessor Pointer Swizzling -


i'm trying avoid problem in static table whereby 1 table references references original table. compiler complains definition of 1 of table members not being found. work around problem, i've been mocking test code, along these lines work? i'm attempting possible?

below code reference:

#define swiztblmax 256  #define term( name , ...) \     static cli_term name { __va_args__ }; swizzle_tbl[__counter__] = { &name, "name" };  typedef struct cli_term {     char* name;     cli_term* parent;     cli_term* child; }cli_termt;  typedef struct swiz_ent {     cli_term* t;     char* n; }swiz_ent;  static swiz_ent swizzle_tbl[swiztblmax];  static cli_term* swizzle(const char* n) {     int i;     for(i=0;i<swiztblmax;i++)     {         if(strcmp(n,swizzle_tbl[i].n)==0)             return swizzle_tbl[i].t;     } return null; }  term( ct_show_test, "test",  swizzle("ct_show"), null ) term( ct_quit, "quit", null, null ) term( ct_show, "show", null, swizzle("ct_show_test") ) 

so, idea defer pointer assignment runtime, i've done similar when writing objects disk , back. there way can create static table this? (with pointers other structs statically assigned)

your term macro cannot used outside scope of function because tries write assignments instead of declarations:

#define term( name , ...) \     static cli_term name { __va_args__ }; \     swizzle_tbl[__counter__] = { &name, "name" }; 

the swizzle_tbl[__counter__] assignment; can't assignments outside of function. must upgraded assign compound literal:

#define term( name , ...) \     static cli_term name { __va_args__ }; \     swizzle_tbl[__counter__] = (swiz_ent){ &name, "name" }; 

using term inside function may or may not help; static cli_term variables won't accessible outside function except via swizzle_tbl. may thing. if else ok (nothing else needs access data name), should ok.

you'd need think __counter__ does. not part of standard c, , therefore isn't portable. use local variable in function in place of __counter__.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -