Go Down

Topic: Function pointer to non-void function (Read 1 time) previous topic - next topic

juliangall

What am I doing wrong here? This compiles:

Code: [Select]
void myfunc(int a, char *s) {
}

void test2(void (*process_function)(int, char *)) {
}

void test1() {
 test2(myfunc);
}


However, when I change myfunc to return an integer, I get a compile error. i.e.

Code: [Select]
int myfunc(int a, char *s) {
 return 1;
}

void test2(int (*process_function)(int, char *)) {
}

void test1() {
 test2(myfunc);
}


The error is "error: variable or field 'test2' declared void In function 'void test1()':". It doesn't seem to like the function pointer referring to a function that returns a value. Any ideas?

Thanks,

Julian

mem

#1
Jan 17, 2009, 07:59 pm Last Edit: Jan 17, 2009, 08:01 pm by mem Reason: 1
try adding [glow]#undef int [/glow] before that code.

There are some macros in wiring.h that define int that may be interfering with your code.

juliangall

You are a genius! Thanks very much. Using uint8_t, uint16_t, etc. works as expected.

Julian

Go Up