First of all, please be aware that I thought the word "dats" was actually a legitimate word somewhere in the C++ language, one that I did not know anything about. I did, indeed, try to find a reference to it. My statement wasn't meant to be a criticism at all. Sorry for the confusion, and sorry to be clueless on seeing that it was a simple typo.
As for what works and doesn't work when compiling, I wrote the following code:
Code: Select all
template <typename T>
inline T const& Max (T const& a, T const& b) {
return a < b ? b : a;
}
void setup() {
Serial.begin(115200);
delay(1000);
int NumAs_int = 5;
long int NumAs_long_int = 5;
int8_t NumAs_int8_t = 5;
int16_t NumAs_int16_t = 5;
int32_t NumAs_int32_t = 5;
NumAs_int = max(NumAs_int, 6);
// NumAs_long_int = max(NumAs_long_int, 6);
// NumAs_int8_t = max(NumAs_int8_t, 6);
// NumAs_int16_t = max(NumAs_int16_t, 6);
// NumAs_int32_t = max(NumAs_int32_t, 6);
NumAs_int = Max(NumAs_int, 6);
// NumAs_long_int = Max(NumAs_long_int, 6);
// NumAs_int8_t = Max(NumAs_int8_t, 6);
// NumAs_int16_t = Max(NumAs_int16_t, 6);
NumAs_int32_t = Max(NumAs_int32_t, 6);
Serial.print("NumAs_int: "); Serial.println(NumAs_int);
Serial.print("NumAs_long_int: "); Serial.println(NumAs_long_int);
Serial.print("NumAs_int8_t: "); Serial.println(NumAs_int8_t);
Serial.print("NumAs_int16_t: "); Serial.println(NumAs_int16_t);
Serial.print("NumAs_int32_t: "); Serial.println(NumAs_int32_t);
}
void loop() {
}
All of the lines commented out throw a compiler error when compiling for an ESP32, for the reasons you described above, and all work fine for an AVR. Interesting that the template process allows int32_t to sneak in and work OK for an ESP32.
I went down this bunny hole after reading another post in this forum about arithmetic that uses int variables taking longer to execute than arithmetic using int16_t or int32_t variables. I had a piece of code where efficiency was important, and I converted some int declarations to int16_t, and the fun began.
And I fully recognize that the AVR compiler operates at a level of abstraction targeted to makers wanting to blink LEDs, read sensors and move servos, and that a professional software engineer writing critical firmware for an ESP32 has different needs and expectations about C++ rigor.