I'm trying to build a module table for my application.
/*** MODULE TABLE DEFINTION ***/
struct ModuleInfo
{
char use_module; // 0 = don't use, 1 = use, -1 for end of list
char module_name[64]; // english name of module
int(*module_init)(void); // module initialization callback
void(*module_tick)(void); // module tick callback
void(*module_end)(void); // module end callback
void *config_table; // config table
};
/*** MODULE TABLE ***/
const struct ModuleTable module_table[] = {
{
1, "GPS/NMEA over RS232",
gps_nmea_rs232_init,
gps_nmea_rs232_tick,
gps_nmea_rs232_end,
NULL
},
// end ta开发者_Go百科ble
{
-1, NULL, NULL, NULL, NULL
}
};
The table stores a list of modules, with pointers to initialization, tick and termination functions to be called at appropriate intervals.
I am building this using MPLAB C30, which is a version of GCC 3.23 (I think?) for specific PIC microcontrollers.
However when I try to compile this, I get:
In file included from main.c:3:
modules.h:67: error: array type has incomplete element type
The table should be const if possible because I have lots of (edit: ROM) spare and not much (edit: RAM) spare. I cannot figure out why this is not working.
Actually that is the problem...
declaring
const struct ModuleTable module_table[] = ...
is a valid C construct without defining struct ModuleTable explicitly; which is why your code is failing, change that line to say
const struct ModuleInfo module_table[] = ...
{
-1, NULL, NULL, NULL, NULL
}
is missing a value, isn't it? I count six fields in the struct.
精彩评论