From: Vincent T. <vt...@un...> - 2010-04-06 05:34:32
|
Hey I have a problem with flexible array and gcc 3.4.5. Basically: typedef struct Desc Desc; struct Desc { void (*func)(int i); int i; }; typedef struct Foo Foo; struct Foo { const char *name; const Desc desc[]; }; #define CALLBACK(cb,i) { cb, i } #define SENTINEL { NULL, 0 } const Foo foo = { "foo", { CALLBACK(my_f, 1), CALLBACK(my_cb, 2), SENTINEL } }; 1) When my_f() is a static function no problem 2) When my_cb() is a function that is defined in a dll, I have the error: struct.c:33: error: initializer element is not constant struct.c:33: error: (near initialization for `foo.desc[1].func') struct.c:33: error: initializer element is not constant struct.c:33: error: (near initialization for `foo.desc[1]') struct.c:34: error: initializer element is not constant struct.c:34: error: (near initialization for `foo.desc[2]') struct.c:35: warning: initialization of a flexible array member struct.c:35: warning: (near initialization for `foo.desc') struct.c:35: error: initializer element is not constant struct.c:35: error: (near initialization for `foo.desc') On linux (newer gcc, though), there is no problem. I didn't try with MinGW gcc >= 4.* I have attached the 3 files that I used to test that problem (compilation commands are at the top of each source file). Does someone know how I can use a function in a DLL in a flexible array ? thank you Vincent Torri |