arduino/Arduino — pull request #1762 by matthijskooijman (2013-12-24 12:12:14+00:00)
Title: Support both char* and uint8* in Stream and Print

Before, a program like this would fail:

void setup(){
uint8_t foo[4];
Serial.readBytes(foo, 4);
Serial.write(foo, 4);

char bar[4];
Serial.readBytes(bar, 4);
Serial.write(bar, 4);
}

Test15.ino: In function ‘void setup()’:
Test15.ino:3:25: error: invalid conversion from ‘uint8_t* {aka unsigned char*}’ to ‘char*’ [-fpermissive]
[...]
Stream.h:76:10: error: initializing argument 1 of ‘size_t Stream::readBytes(char*, size_t)’ [-fpermissive]
size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer
^
Test15.ino:8:21: error: invalid conversion from ‘char*’ to ‘const uint8_t* {aka const unsigned char*}’ [-fpermissive]
[...]
Print.h:53:20: error: initializing argument 1 of ‘virtual size_t Print::write(const uint8_t*, size_t)’ [-fpermissive]
virtual size_t write(const uint8_t *buffer, size_t size);

As you can see, it doesn't matter if you use a char[] or uint8_t[], both will
fail. This is because Print::write only worked with uint8_t buffers and
the Stream methods only work with char buffers.

These commits make both of them work with both types of buffers. By
putting the definitions in the .h file, the compiler can just inline
them, meaning there is no impact on the generated code size.