I have been trying to write an array of characters to a file in the SDcard using the write function.
The definition of the funtion in the arduino.cc is the following:
write()
Description
Write data to the file.
Syntax
file.write(data)
file.write(buf, len)
Parameters
file: an instance of the File class (returned by SD.open())
data: the byte, char, or string (char *) to write
buf: an array of characters or bytes
len: the number of elements in buf
Shouldn´t i be able to do the following, declarations and use of the write function:
They refer that: buf: an array of characters or bytes
So it should accept a char array, no?
Apparently if you define byte you don´t even need to do the cast.
If you define as char array and do the cast to (byte *) it works to.
But, using char array and no cast it doesn´t work, can you explain? shouldn´t char work, or there is a small error in the documentation?
So char should work according to the documentation, no?
Yes, but that does NOT necessarily mean without a cast.
Keep in mind that sometimes documentation is written before the code, and sometimes it's written by people that couldn't code there way out of a wet paper bag.
The REAL documentation is in the .h and .cpp files.
Unfortunately the Arduino online API documentation is very poor and doesn't actually provide the information a programmer would need to use the API. This lack is quite surprising, given how many ways there are nowadays to autogenerate this type of documentation from the code. As a result, people coding against the API and needing to know what the actual method signatures are, are left having to look at the code for themselves. Of course, the documentation doesn't even provide any reference to the relevant source code so we're left to find this for ourselves too. It's nice having a free IDE and a free runtime library, but free software comes at a cost. In this case, the cost is quality.
Watch the subtle difference between a character and a char .
To add to PeterH's faster response:
Be happy they use the avrgcc compiler as is, and don't write their own, just to implement it the way they document it.
Documentation is nice, but if in doubt, read the include file.
If still in doubt, reat the source code, it's open.
My main worry was that i didn´t understood the behaviour of the compiler accordingly to the documentation...
I failed to consult the code, should have done that...