views:

46

answers:

2

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 table
 {
  -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.

+1  A: 
{
  -1, NULL, NULL, NULL, NULL
 } 

is missing a value, isn't it? I count six fields in the struct.

Will A
Thanks for pointing that out, but it didn't fix it... still same error. I thought C fills in blank values (with zero/NULL) anyway?
Thomas O
It probably does, or at least should. How about having module_table[2] rather than module_table[], just in case that matters.
Will A
+1  A: 

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[] = ... 
Elf King
Thanks for pointing that out. Just a silly typo. It compiles fine now. :)
Thomas O