
Originally Posted by
Theremingenieur
Just discovered another issue: Even the "simple" Serial.println() does some unexpected and weird variable casting.
printing a int8_t (signed byte) which contains a negative value gives a int32_t output. WHY???
That is because there is no version of the Print class that takes signed char (i.e. int8_t) as a type, and the compiler does the standard conversions to one of the types that have alternates in Print.h. The C/C++ languages first convert signed char/short to int. On the arm platform, int is a 32-bit type. On the AVR platform (like the Arduino), int is a 16-bit type.
Code:
size_t print(unsigned char n, int base) { return printNumber(n, base, 0); }
size_t print(int n, int base) { return (base == 10) ? print(n) : printNumber(n, base, 0); }
size_t print(unsigned int n, int base) { return printNumber(n, base, 0); }
size_t print(long n, int base) { return (base == 10) ? print(n) : printNumber(n, base, 0); }
size_t print(unsigned long n, int base) { return printNumber(n, base, 0); }