Go Down

Topic: error: expected ';', ',' or ')' before '&' token (Read 8 times) previous topic - next topic

capsid

Hi there!  I'm getting a strange error when I try to pass a struct to a function by reference.
Code: [Select]
error: expected ';', ',' or ')' before '&' token

It errors on the first line of this function definition in file "channel.c":
Code: [Select]
void initChannel(struct Channel &chan){
 chan.state = OFF;
 chan.dirty = 1;
 initPWM(chan.pwm);
}


The compile-results box shows the same error for all of the similar function prototypes in my header file "custom_types.h".   This led me to believe that I couldn't pass structures by reference, but I made another sketch in which I passed structures (and structures in structures) by reference and it compiled with no problems.  

Here's an excerpt from "custom_types.h", so you can see if I'm doing something obviously wrong:
Code: [Select]
struct PWM{
 int duty;  
 int state;
 long lastUpdate;
 int updateInterval;
 int onInterval;
 int offInterval;
};

void initPWM(struct PWM &pwm);           //errors on this line
boolean updatePWM(struct PWM &pwm);   //and this one


struct Channel{
 int pin;
 int color;
 int state;
 
 boolean dirty;
 
 struct PWM pwm;  
};

void initChannel(struct Channel &chan);   //error here, too
void updateChannel(struct Channel &chan);  //and again...


I'd be very grateful for some hints on what to try next, or what other info I can provide.   For the record, I do include "custom_types.h" in several files, including the main sketch file.  I also include "WProgram.h" in "custom_types.h" so I can have access to certain constants like HIGH and LOW.

Thanks for your help:)

AlphaBeta

How about:
Code: [Select]
typedef struct {
 int pin;
 int color;
 int state;
 
 boolean dirty;
 
 struct PWM pwm;  
} Channel;

void initChannel(Channel &chan);   //error here, too
void updateChannel(Channel &chan);  //and again...


capsid

Unfortunately, that yields an identical set of errors.  

That's similar to how I did it at first.  I prefixed the type declarations with 'struct' since I was having errors and hoped to be less ambiguous to the compiler.  

I'm not terribly well grounded in C, which is why I feel like I'm missing something obvious.  I could push the project (and its many tabs) to my github if that would make it easier to find the problem.

Thanks, though, for any and all suggestions.

Kristian

Hi,

I simply copied your code, but it compiles. I'm using version 00018.
So I'm not sure what is wrong...

Quote

struct PWM{
  int duty;  
  int state;
  long lastUpdate;
  int updateInterval;
  int onInterval;
  int offInterval;
};

void initPWM(struct PWM &pwm);           //errors on this line
boolean updatePWM(struct PWM &pwm);   //and this one


typedef struct {
  int pin;
  int color;
  int state;

  boolean dirty;

  struct PWM pwm;
} Channel;

void initChannel(Channel &chan);   //error here, too
void updateChannel(Channel &chan);  //and again...

void setup()
{
  
}

void loop()
{
  
}



halley

Probably missing a semicolon WAY before this token.  Such as at the end of a struct or class declaration, just after the curly brace closes.  Easy semicolon to forget.

Go Up