1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-16 00:43:00 +03:00

Add explicit Print::write(char) (#6101)

W/o this change, file::write('a'); tries to use the template and fails
since char is a basic type.

The reason it is needed is due to pre 2.5.x behavior, File::write(char)
silently was cast to File::write(uint8_t).  With the template write,
though, this is not performed.

* Add Print::write tests and add'l overrides

Ensure that print::write does something sane and doesn't cause a compile
time error about templates when used for Files.

Test using SPIFFS file since Print is an abstract type.
This commit is contained in:
Earle F. Philhower, III
2019-05-18 14:07:13 -07:00
committed by GitHub
parent 48fc8aff20
commit 82adc95d64
4 changed files with 91 additions and 11 deletions

View File

@ -63,12 +63,15 @@ class Print {
return write((const uint8_t *) buffer, size);
}
// These handle ambiguity for write(0) case, because (0) can be a pointer or an integer
size_t write(short t) { return write((uint8_t)t); }
size_t write(unsigned short t) { return write((uint8_t)t); }
size_t write(int t) { return write((uint8_t)t); }
size_t write(unsigned int t) { return write((uint8_t)t); }
size_t write(long t) { return write((uint8_t)t); }
size_t write(unsigned long t) { return write((uint8_t)t); }
inline size_t write(short t) { return write((uint8_t)t); }
inline size_t write(unsigned short t) { return write((uint8_t)t); }
inline size_t write(int t) { return write((uint8_t)t); }
inline size_t write(unsigned int t) { return write((uint8_t)t); }
inline size_t write(long t) { return write((uint8_t)t); }
inline size_t write(unsigned long t) { return write((uint8_t)t); }
// Enable write(char) to fall through to write(uint8_t)
inline size_t write(char c) { return write((uint8_t) c); }
inline size_t write(int8_t c) { return write((uint8_t) c); }
size_t printf(const char * format, ...) __attribute__ ((format (printf, 2, 3)));
size_t printf_P(PGM_P format, ...) __attribute__((format(printf, 2, 3)));