syntax of Serial.println not checked ?

Hi all,

I have observed VERY strange behaviour, which
I cannot reproduce yet (like a looping setup(), print statements not being executed etc.)

But I CAN present you this one :

Serial.println("hello !"); // double quotes, no problem
Serial.println('hello !'); // single quotes, no parser error, response is a number...

I get the feeling the Serial Library is less than stable, but I found surprising little complaints about it. so it is probably me....
:frowning:

It is not quite clear to me if a sketch is ultimately C code or Java code ?
if it is, it is probably a problem in the underlying compiler.

hope someone can use this to improve Arduino,
it is a very nice platform.

You need to understand the difference between “char” and “char*”, and between single and double quotes.
There is nothing wrong with the print method.

A sketch is C/C++, and yes, I’m sorry, it’s just you :wink:

Here’s something else that won’t give a compiler error:

unsigned long alpha = 'that';

Im not sure I understand what a 'that' is...
as far as I know single quotes are for mentioning a char
where as multichar stuff is "automagically" a (null terminated) string and to note that down I thought i HAD to use double quotes.

I still think (in absense of a deeper insight) that the parser should
warn about a multi-char sequence in single quotes.
is your example actually useful, i.e. are there situations in which that construct is used in anger ?

A 'that' is a multi character constant, assigned here to an unsigned long integer variable.
It is not a string, it simpy consists of the four byte values 0x74 0x68 0x61 0x74. There is no terminating null, as there would be in "that", which would take up five bytes.

It isn't much used in anger, though I have seen it in embedded applications, usually for storing short command mnemonics.
There's nothing in C that forbids it, or give good reason to issue a warning.

ok, thanks.

I'll dig up Kernighan & Ritchie then, and start from there,
now I finally have found something to program.
Yay!