I suspect that's due to these 2 overloads in the base class Print
:
virtual size_t write(uint8_t);
size_t write(const char *str);
If called as write(0)
, the write(const char *)
overload will be selected as a better candidate (the first requires a narrowing conversion, but 0 is a null-pointer).
So to send a 0
byte, you must use an explicit cast to help the compiler choose the right overload: write((uint8_t)0)
.
In addition, you can get a warning "narrowing conversion, possible loss of data" if you let a larger type implicitly convert to a smaller one. So it's always a good idea to use an explicit cast to tell the compiler you know what you're doing.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…