Pages: [1]   Go Down
Author Topic: Function pointer to non-void function  (Read 770 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What am I doing wrong here? This compiles:

Code:
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:
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
Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: January 17, 2009, 02:01:03 pm by mem » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Julian
Logged

Pages: [1]   Go Up
Jump to: