Page 1 of 1

C++ compiler for Sketch ESP32

Posted: Sun Jul 26, 2020 6:43 pm
by rossati
Hi
It is true that the C++ compiler of ESP32 sketchs on Arduino IDE is different from the C++ compile of Arduino Uno board?

Re: C++ compiler for Sketch ESP32

Posted: Sun Jul 26, 2020 8:23 pm
by ESP_Sprite
Define 'different'? It's different in that you cannot use the same compiler programs for both CPUs, as the processor core is entirely different. It's the same in that both are versions of GCC, and they should understand and interpret C++ mostly in the same way.

Re: C++ compiler for Sketch ESP32

Posted: Tue Jul 28, 2020 2:42 pm
by rossati
Thanks ESP_Sprite
my problem is to create a scketch for Arduino and ESP32 boards.
My be the compiler (or the switches) arenn't of the same level, for example the C++ compiler for Arduino accepts the default parameters in function declaration but this not happens for the C++ ESP32 compiler.
Another difference (that I have given me many problems) is the char declaration that for C++ ESP32 isn't signed char.

Re: C++ compiler for Sketch ESP32

Posted: Tue Jul 28, 2020 7:44 pm
by PeterR
My be the compiler (or the switches) arenn't of the same level, for example the C++ compiler for Arduino accepts the default parameters in function declaration but this not happens for the C++ ESP32 compiler.
Another difference (that I have given me many problems) is the char declaration that for C++ ESP32 isn't signed char.
Send the code & the compiler error.
'signed char' is 'signed char'! So you must be wrongly attributing your error. I would be very suprised if ESP QA dropped that ball! Else am I to suppose that a uint16_t might be an int32_t? Worlds would fall. Posts would be err posted ;)
EDIT: Even under C+11 there is latitude and certainly differences between earlier C++ versions. Code snippet & compiler message is the best way.

Re: C++ compiler for Sketch ESP32

Posted: Wed Jul 29, 2020 2:32 pm
by ESP_Sprite
The definition of a 'char' is not specified by the C specs at least iirc; it can be signed or unsigned by default, depending on the architecture; you may be right in that that differs between Xtensa and AVR. From what I know, gcc can change it with a command line option. (Although I'd posit good code would explicitly use an uint8_t or int8_t instead...) No idea wrt default function arguments, from what I can tell that should work; can you post an example of the code and error there?

Re: C++ compiler for Sketch ESP32

Posted: Wed Jul 29, 2020 4:07 pm
by rossati
Thanks ESP_Sprite
I agree with you on the use int8_t instead of char, because there is difference in compiling for Arduino and ESP32: for example if char variable = -1 this instruction mYArray[variable+1]; works in Arduino and crash on ESP32.
For the functions with default variable this is the fragment that works for Arduino:

Code: Select all

...
// .h source
unsigned long clocker(bool ms=false);
...
// .cpp source
unsigned long handleEvents::clocker(bool ms=false) {  // returns time at seconds or at milliseconds if ms=true
  static unsigned long millisOld = 0;
  if (millisOld > millis()) {*ag_Clock += secondsTimerCount;}
  millisOld = millis();
  if (!ms) return (*ag_Clock)+millis()/1000;
  return (*ag_Clock)*1000+millis();
}
Compiling for ESP32 this is the errors list

Code: Select all

Arduino: 1.8.12 (Windows 10), Board: "ESP32 Dev Module, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, None"

handleEvents.cpp:14:50: error: default argument given for parameter 1 of 'long unsigned int handleEvents::clocker(bool)' [-fpermissive]

 unsigned long handleEvents::clocker(bool ms=false) {  // returns time at seconds or at milliseconds if ms=true

                                                  ^

In file included from sketch\handleEvents.cpp:9:0:

sketch\handleEvents.h:60:17: note: previous specification in 'long unsigned int handleEvents::clocker(bool)' here

   unsigned long clocker(bool ms=false);

                 ^

exit status 1
default argument given for parameter 1 of 'long unsigned int handleEvents::clocker(bool)' [-fpermissive]

For completeness the compilation is not aborted in a first attempt where the default declaration was only on the .h script

Re: C++ compiler for Sketch ESP32

Posted: Thu Jul 30, 2020 5:29 am
by markkuk
Default arguments for a function must be defined in the function declaration (in the .h file), not in the definition. Your code is wrong and the compiler is working correctly. http://www.icce.rug.nl/documents/cplusp ... 2.html#l17

Re: C++ compiler for Sketch ESP32

Posted: Thu Jul 30, 2020 7:06 am
by rossati
Tanks markkuk