square Brackets in serial.print()

Hello,
could any of you point out to me what this statement means. I get what it does but where is the syntax discribed.

serial.print(".SL"[event]);

please help

best regards

paul

Standard C subscripting.

I get what it does but where is the syntax discribed.

That would depend on what serial is an instance of.

If it is a typo, then maybe you can begin to understand why we want you to post ALL of your REAL code.

This is usually seen in obfuscated C. The ".SL" returns a pointer to a 4 character array, so ".SL"[event] will return whatever character event indexes.

If event is 0, it returns '.'
if event is 1, it returns 'S'
if event is 2 it returns 'L'
if event is 3 it returns '\0'
if event is something else, it returns garbage.

Thanx a lot!!!
is there by any chance some reference for this sort of pointers? (obfuscated C)
i’m quite new to arduino and C, so any help is appreciated…

best regards

paul

No, run away from this. It adds nothing but confusion.

I disagree that it is obfuscated - it is clear that a subscript operation is taking place.
Compare this to Ada, where without further context, it is impossible to discern whether “A(X)” refers to calling a function called A taking X as a parameter, or retrieving the Xth index of an array called A.

Serial.print(*(".SL" + event));would be obfuscated :smiley:

But indexing a constant string is not that common. You have to know that a constant string decays into a pointer to the string somewhere in memory.

And storing constant strings in SRAM is a bad idea on the Arduino.