Char is not signed - no reference in the documentation

Which board are you using ?

!!! Completely missing the point !!!

An Uno and a generic ESP32.

I think the OP code does a cast of the result of read(), and the issues are due to the cast, rather than the return value of the read().

The title of this thread was changed from

Serial.read get question marks

to

Serial.read does not return '-1'

This was unfortunate, because the focus of the thread is about casting the -1 return from Serial.read( ) to 'char' on different platforms.

You didn't read the thread. I'm sorry. Unfortunately, the cause of the problem was not entirely clear at the beginning because the documentation is incomplete.

I have changed the title for the 3rd time.

2 Likes

I think that is disingenuous bearing in mind the replies and discussion which were based the two previous versions of the topic title

How should I do it?
Should more people like DaveX answer something inappropriate without reading the thread? Should I explain to everyone what it's all actually about?

I like the titles to match the thread for posterity so that future readers could know if it was worth reading.

I did read the thread, because it seemed like a lot of discussion about a broken Serial.read(). It turned out to be more an argument that the sign of a bare "char" is undefined than that read() is broken.

If the code depends on signed char behavior, declare signed char c. The code would also work on both systems if it explicitly checked for the char(-1) instead of just the sign of an unspecified sign type.

  else if ( c != char(-1) &&  (c >= 32) && ( data.index < LENGTH) ) { // if there is still space in the buffer,

Beware of the portability of "char".

Once the topic wandered off the subject of its original title, or was it the second version of the title, and became focussed more on whether or not a char variable is signed it might have been more appropriate to have started a new topic

DaveX:
Thanks for the tip. There will be many solutions. Also signed char is very good. Thank you. Extra queries are not needed for this. It is adequate if c is defined with signed char.

UKHeliBob:
I could have done everything. Unfortunately not possible. :wink:

Nobody changes anything in the documentation anyway. After all, ptillisch and oqibidipo made it very clear to me.

The topic is exhaustively explained. Nobody changes anything in the documentation anyway. As ptillisch and oqibidipo have made very clear to me. I won't write anything more on the subject.

I have also learned a lesson from this. I will never again defend Arduino in another forum.

Goodbye.