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
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy