Pages: [1]   Go Down
Author Topic: typedef in function definition has a problem  (Read 3388 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The following program produces a compiler error (Arduino 0011 alpha):
struct foo{
  int    a;
  int    b;
};
typedef struct foo FOO;
FOO  myvar[21];
FOO *myFunct(){}
void setup(){}
void loop(){}

ERROR is: error: expected constructor, destructor, or type conversion before '*' token
If I change
<FOO *myFunct(){}>
to
<struct foo *myfunct(){}> it compiles just fine.

Mike...
mikeasl@mac.com
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 11
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to put type definition inside a separate header file, as the function prototypes that are generated by the IDE are inserted above the typedef (but below pre-processor directives like #include).  This header can be another tab in your sketch; use the right facing arrow in the upper right of the IDE.
Logged

Pages: [1]   Go Up
Jump to: