-->
Page 1 of 2

Change of global state enum to int value in a function

PostPosted: Wed Feb 21, 2018 6:10 am
by lcharpen17
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:

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


Here is a simplified example of the problem:


Code: Select allenum {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..

Re: Change of global state enum to int value in a function

PostPosted: Thu Feb 22, 2018 7:56 pm
by tele_player
This is correct behavior. NouveauCycle is not a valid value to assign to CYCLE_ARROSAGE. Only the members listed in the enum can be assigned.

Re: Change of global state enum to int value in a function

PostPosted: Fri Feb 23, 2018 10:03 am
by mrburnette
I ran the same code for Generic ESP8266 Module, 80MHz, DIO, 115200, 512K (64K SPIFF)

The code compiled without error:
Code: Select allArchiving built core (caching) in: /tmp/arduino_cache_430938/core/core_esp8266_esp8266_generic_CpuFrequency_80,FlashFreq_40,FlashMode_dio,UploadSpeed_115200,FlashSize_512K64,ResetMethod_ck,Debug_Disabled,DebugLevel_None_____e309d7f2e5c52c64897dde81c89148e3.a
Linking everything together...
"/home/ray/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-gcc" -g -w -Os -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static "-L/home/ray/.arduino15/packages/esp8266/hardware/esp8266/2.3.0-rc2/tools/sdk/lib" "-L/home/ray/.arduino15/packages/esp8266/hardware/esp8266/2.3.0-rc2/tools/sdk/ld" "-Teagle.flash.512k64.ld" -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,register_chipv6_phy  -o "/tmp/arduino_build_243985/junk.ino.elf" -Wl,--start-group "/tmp/arduino_build_243985/sketch/junk.ino.cpp.o" "/tmp/arduino_build_243985/arduino.ar" -lm -lgcc -lhal -lphy -lpp -lnet80211 -lwpa -lcrypto -lmain -lwps -laxtls -lsmartconfig -lmesh -lwpa2 -llwip_gcc -lstdc++ -Wl,--end-group  "-L/tmp/arduino_build_243985"
"/home/ray/.arduino15/packages/esp8266/tools/esptool/0.4.8/esptool" -eo "/home/ray/.arduino15/packages/esp8266/hardware/esp8266/2.3.0-rc2/bootloaders/eboot/eboot.elf" -bo "/tmp/arduino_build_243985/junk.ino.bin" -bm dio -bf 40 -bz 512K -bs .text -bp 4096 -ec -eo "/tmp/arduino_build_243985/junk.ino.elf" -bs .irom0.text -bs .text -bs .data -bs .rodata -bc -ec
Sketch uses 221947 bytes (51%) of program storage space. Maximum is 434160 bytes.
Global variables use 31520 bytes (38%) of dynamic memory, leaving 50400 bytes for local variables. Maximum is 81920 bytes.


Code: Select all
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() {
}

Re: Change of global state enum to int value in a function

PostPosted: Fri Feb 23, 2018 12:06 pm
by tele_player
mrburnette : your code is valid. The code in the original post is not.

CYCLE_ARROSAGE is a variable which can only hold values listed in the enum.