Change of state enum to int value in a function

Hello,

It's been several months since I have a compilation error on when I want to change the value of an enumeration declared at the beginning of the program (global), in a function that replaces it with an integer.

Before I did not have this problem, but having switched my code from a mini arduino card, to ESP8266 the problem appeared .. It do not have the same compiler ??

The error below is still blocking and prevents me from advancing on my project .. I can not find the solution:

ERROR : request for member 'state' in 'CYCLE_ARROSAGE', which is of non-class type '<anonymous enum>'

Here is a simplified example of the problem:

enum {S, // SECURITE
N, // NUIT
J1_1, J1_2, J1_3,  // Luminosité 1
J2_1, J2_2, J2_3,  // Luminosité 2
J3_1, J3_2, J3_3, // Luminosité 3
} CYCLE_ARROSAGE; // SECURITE



void setup () {

CYCLE_ARROSAGE = N; // OK
  
}




void loop () {

CheckChangementCycleArrosage(J2_2);

}






void CheckChangementCycleArrosage(int NouveauCycle ){

 if(CYCLE_ARROSAGE != NouveauCycle){

  Serial.print("CYCLE CHECKE : ");
  Serial.println(NouveauCycle); // -> 6

  Serial.print("CYCLE CHECKE CAST: ");
  Serial.println(String(NouveauCycle)); // -> 6

  Serial.print("CYCLE ARROSAGE: ");
  Serial.println(CYCLE_ARROSAGE); // -> 1
  

  CYCLE_ARROSAGE = NouveauCycle; // -> ERROR

}

What could be the solution? I do not understand..

Using IDE 1.8.5 the example code compiles if you add the missing '}' at the end of the source. It does not give the error message you quote. It just gives the warning

44:20: warning: invalid conversion from 'int' to '<anonymous enum>' [-fpermissive]
     CYCLE_ARROSAGE = NouveauCycle; // -> ERROR

But I don't understand what the code is trying to do.

Thank you for the answer,

I also use Arduino IDE 1.8.5 but to upload to an ESP8266 card.
Before actually I did not have the error on my arduino mini ...

A solution at the configuration level or in the code?

I have never used a ESP8266 so can't help further.

Okay thanks, can someone else help me ??????

As the error message states thatthe enum is anonymous you might try adding a name

enum CYCLE_TYPE {S, // SECURITE
N, // NUIT
J1_1, J1_2, J1_3,  // Luminosité 1
J2_1, J2_2, J2_3,  // Luminosité 2
J3_1, J3_2, J3_3, // Luminosité 3
} CYCLE_ARROSAGE; // SECURITE

Enums and ints are not compatible in C++.
Give your enum a name and use it as the parameter type:

enum SomethingSomething { ... } CYCLE_ARROSAGE;

void CheckChangementCycleArrosage(SomethingSomething NouveauCycle) {

lcharpen17:
The error below is still blocking and prevents me from advancing on my project .. I can not find the solution:

Name the enum and then use that type for the function parameter like:

enum CYCLE_ENUM{S, // SECURITE
N, // NUIT
J1_1, J1_2, J1_3,  // Luminosité 1
J2_1, J2_2, J2_3,  // Luminosité 2
J3_1, J3_2, J3_3, // Luminosité 3
};

CYCLE_ENUM CYCLE_ARROSAGE; // SECURITE

and...

void CheckChangementCycleArrosage(CYCLE_ENUM NouveauCycle ){

Yours,
TonyWilk

edit: @oqibidipo... snap ! :slight_smile:

stowite:
Using IDE 1.8.5 the example code compiles if you add the missing '}' at the end of the source. It does not give the error message you quote. It just gives the warning

44:20: warning: invalid conversion from 'int' to '<anonymous enum>' [-fpermissive]

CYCLE_ARROSAGE = NouveauCycle; // -> ERROR

When you see a warning accompanied with >:( >:( >:( -fpermissive >:( >:( >:( it is really an error.

(That >:( thing was added to default compiler options in the AVR core after GCC was updated to newer version that has stricter error checking and a number of libraries failed to compile.)