error: variable or field declared void

What's my mistake with this code ?

error: variable or field 'setFunction' declared void

/*
callback
*/

#ifndef NULL
#define NULL 0
#endif

typedef void (*FnPtr)();   
static FnPtr activeFunction = NULL;


void setup() {
  Serial.begin(9600);
}

void loop() {
}

void setFunction(UtilFnPtr useThisFn) {  
  activeFunction = useThisFn;
}

wally

What is your objective with this code? The only thing you have that makes any kind of since that will compile is this.

void setup() {
  Serial.begin(9600);
}

void loop() {
}

Make this change...

void setFunction([glow]FnPtr[/glow] useThisFn) {

Hmm, looks like something is broken here.

(I've only just noticed that it's odd that "typedef" isn't highlighted in the IDE!).

@digimike: Apart from the "UtilFnPtr" typo, this really ought to work - it makes pretty good sense.

[edit]Woah! Bizarre!

typedef int (*FnPtr)(void);

FnPtr activeFunction =  NULL;

void setup() {
  Serial.begin(9600);
}

void loop() {
}

void setFn (long useThisFn) {  
  activeFunction = (FnPtr) useThisFn;
}

[/edit]

Sorry for the typo error FnPtr / UtilFnPtr, but this does not change the problem.

typedef is not highlighted, correct.
here again the not running code in v 017.

/*
callback
*/

#ifndef NULL
#define NULL 0
#endif

typedef void (*FnPtr)();  
static FnPtr activeFunction = NULL;


void setup() {
  Serial.begin(9600);
}

void loop() {
}

void setFunction(FnPtr useThisFn) {  
  activeFunction = useThisFn;
}

Testing "struct" and "typedef" in a separate testprogram works nice.
Both "struct" and "typedef" are not highlighted, but seems to work.

struct myStruct {
  int a;
  int b;
};

typedef struct myStruct XYCoord;

XYCoord pointA;

void setup() {
  Serial.begin(9600);
  pointA.a = 77;
  pointA.b = 88;
}

void loop() {
  delay(1000);
  Serial.print(pointA.a, DEC); 
  Serial.print("\t");
  Serial.println(pointA.b, DEC); 
}

@Grove:
Your suggestion compiles without errors, but its really little strange.
Can you explain the reasons for my problem in previous code and your solution ?

The Arduino IDE extracts function prototypes from the Sketch and places them at the top. The modified text is then passed to the compiler. Essentially, the Sketch becomes this...

void setup();
void loop();
void setFunction( FnPtr useThisFn );

/*
callback
*/

#ifndef NULL
#define NULL 0
#endif

typedef void (*FnPtr)();  
static FnPtr activeFunction = NULL;

void setup() 
{
  Serial.begin(9600);
}

void loop() 
{
}

void setFunction( FnPtr useThisFn ) 
{  
  activeFunction = useThisFn;
}

One solution is to move the typedef to a header file then include the header file in your Sketch.

A small grievance about Groove's example: the parameter really should be unsigned (or int) instead of long...

void setFn (unsigned useThisFn) {

Thank You, now it works as expected.
below the working code:

file utils.h

/*
 * utis.h
 */

typedef void (*FnPtr)();

file main.pde

/*
callback
*/
#include "utils.h"

#ifndef NULL
#define NULL 0
#endif

static FnPtr activeFunction = NULL;

void setup() {
  Serial.begin(9600);
  setFunction(Pong);
}

void loop() {
  delay(2000);
  activeFunction();
}

void setFunction( FnPtr useThisFn ) {  
  activeFunction = useThisFn;
} 

void Ping () {
  Serial.println("Ping");
} 

void Pong() {
  Serial.println("Pong");
}