Hello, I recently bought a zero and started carrying over some of my sketches (previously have been using a Duemilanove) but have run into compatibility problems. After a while I've traced it down to the zero seemingly treating char as unsigned rather than unsigned.
I have run the following code on the two arduinos to test the treatment of char (and compared to byte):
Perhaps I should have excluded some of those cases such as -256 which were just me making sure I understood what was going on.
It's the -1 case which has caused me trouble. Why is the Arduino Zero giving 255 in the output for that example (c[2]) given the convention that you mentioned?
Unfortunately I think I am missing something in what you are saying because I think I already understand the point you are making but it doesn't appear to me to explain the difference in result between the two boards. Char should be signed and so I should get -1 in both cases.
Can you please confirm that you would expect the difference in output for the above sketch for the two boards?
Are you hinting perhaps that it's a result of the Zero board being 32-bit rather than 8-bit?
the "C" language doesn't define if "char" is signed or unsigned, but this is platform dependent.
Remember that DUEMILANOVE is AVR based and ZERO is ARM based.
If you want portability of your code it is a bad habit to use "char" to do math.
If you need math use "signed char" or "unsigned char", never "char".
Use "char" only for printable characters.
As a patch for allow portability to code that doesn't follow this rules try to put this at the beginning of your code: