0

In some IDEs I am given an error for this yet in others it works fine. I would like to know what the problem is and what i can do to fix it.

typedef enum custom_brake
{
  BRAKE_COAST = 0,
  BRAKE_BRAKE = 1,
  BRAKE_HOLD = 2

} TokenType;

void GsetBrakeMode(custom_brake brakeMode){
  switch(brakeMode){
    case BRAKE_COAST: break;
    case BRAKE_BRAKE: break;
    case BRAKE_HOLD: break;
  }
}

GsetBrakeMode(BRAKE_HOLD);
Grimm_boss
  • 15
  • 4
  • Edit: it works when i have it inside of a function but not directly after the initialization, I'm not sure why but and I would still like to know why some IDEs accept it and some dont. – Grimm_boss Jun 15 '21 at 18:33

1 Answers1

1

GsetBrakeMode(BRAKE_HOLD); is a function call. You cannot place that outside function body without some trick.

Place that inside some function body like this:

void someFunc(void) {
    GsetBrakeMode(BRAKE_HOLD);
}

One of the trick to write that outside function body is placing that in an expression to determine initial value of a variable:

int variableForTrick = (GsetBrakeMode(BRAKE_HOLD), 0);
MikeCAT
  • 73,922
  • 11
  • 45
  • 70