There is an inconsistency between actual behavior and the arduino documentation.
http://arduino.cc/en/Reference/StringConstructorhttp://arduino.cc/en/Serial/PrintAccording to the documentation, a String can be initialized using a constant
in the form of "some text here". However this fails to add a null terminator to
the end of the String. As such this code does not work:
String settings[]={
"CURSOR_DRIVER"
"BRLTTY_DRIVER"
"BUFFER_SIZE_MAX"
"BUFFER_COLUMNS"
"BUFFER_ROWS"
"DOTCOUNT"};
void setup() {
Serial.begin(9600);
Serial.println(settings[0]);
}
void loop() {
// put your main code here, to run repeatedly:
}
It prints:
CURSOR_DRIVERBRLTTY_DRIVERBUFFER_SIZE_MAXBUFFER_COLUMNSBUFFER_ROWSDOTCOUNT
(Along with no amount of garbage, if there doesn't happen to be a \0 somewhere
in the next kilobyte of memory...)
While this code does work:
String settings[]={
"CURSOR_DRIVER\0"
"BRLTTY_DRIVER\0"
"BUFFER_SIZE_MAX\0"
"BUFFER_COLUMNS\0"
"BUFFER_ROWS\0"
"DOTCOUNT\0"};
void setup() {
Serial.begin(9600);
Serial.println(settings[0]);
}
void loop() {
// put your main code here, to run repeatedly:
}
It prints:
CURSOR_DRIVER
I must note, that this is really only a problem in documentation.
The documentation for the print command clearly states that it works on any
data type:
http://arduino.cc/en/Serial/Printval: the value to print - any data type
And yet in reality, it works on NULL terminated strings but not length bounded
Strings....
I am on Arch linux.
$pacman -Q arduino
arduino 1:1.0-2
$ uname -a
Linux timothy 3.2.5-1-ARCH #1 SMP PREEMPT Tue Feb 7 08:46:10 UTC 2012 i686 Intel(R) Core(TM)2 Duo CPU L7500 @ 1.60GHz GenuineIntel GNU/Linux
Timothy Hobbs