1

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.

5
  • What is on line 67? What is the definition of struct ModuleTable? Commented Jul 17, 2010 at 18:59
  • 3
    Do you mean to have module_table be an array of ModuleInfo? Commented Jul 17, 2010 at 19:05
  • I believe (haven't tested) that the last initialization will put the 4 NULLs all into the first 4 elements of the 64 element char array. You would need to say { -1, { 0 }, NULL, NULL, NULL } to initialize the array and then go on. In any case, that should not cause such an error message though. You don't need the NULL initializers explicitly either. It suffices to say { -1 } for the last: Everything else will be NULL (or '\0' in the case of the char array) automatically. Commented Jul 17, 2010 at 19:13
  • @deinst please put an answer. i don't want to answer now since it looks like i stole your insights :) Commented Jul 17, 2010 at 19:17
  • @Johannes Feel free to steal. Someone already has. Thanks for being honest though. Commented Jul 17, 2010 at 19:59

2 Answers 2

1

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[] = ... 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for pointing that out. Just a silly typo. It compiles fine now. :)
1
{
  -1, NULL, NULL, NULL, NULL
 } 

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

2 Comments

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?
It probably does, or at least should. How about having module_table[2] rather than module_table[], just in case that matters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.