Implementing a callback

Standard C code for doing a callback will not compile. Any ideas how to get around the problem?



static void (*fx_)(char * frame);    // Storage for the callback pointer

// Registration routine
void reg(void (*fx)(char * frame)) {

  // Save the user's pointer 
  fx_ = fx;

}

// Sample of calling the callback.
void callCallback(void) {
  if (fx_ != NULL) {
    fx_("aaa");
  } else {
    printf("Callback not set");
  }
}


Dynamic C starts to barfs on the syntax of
static void (*fx_)(char * frame);

with the following errors:

line 4829 : ERROR CHARIOT.C    : Bad declaration: ',' ';' or '=' expected.
line 4829 : ERROR CHARIOT.C    : Syntax error - or garbage at end of program.
line 4829 : ERROR CHARIOT.C    : Need function definition or declaration.
line 4829 : ERROR CHARIOT.C    : Missing character ';'.                 
line 4829 : ERROR CHARIOT.C    : Bad declaration: ',' ';' or '=' expected.
line 4829 : ERROR CHARIOT.C    : Missing character ';'.                 

My implementation would be an order of magnitude simpler with callbacks. Any help here would be greatly appreciated.

-Skye

Dynamic C does not like the arguments of a function pointer to be defined. They must be left blank. So this code does seem to work:

static void (*fx_)();    // Storage for the callback pointer

// Registration routine
void reg(void (*fx)()) {

  // Save the user's pointer 
  fx_ = fx;

}

// Sample of calling the callback.
void callCallback(void) {
  if (fx_ != NULL) {
    fx_("aaa");
  } else {
    printf("Callback not set");
  }
}

It is now left to the user to insure the arguments match. (BOOOO).

-Skye