Volatile String Object?

I want to have a Sting object that is modified in an interrupt and printed in the main code. Declaring it as volatile like this does not compile:
volatile String debugBits = "Bits seen: ";

It gives an error message:
"no matching function for call to 'String::String(volatile String)'

Do I need 'volatile' to be sure that the latest string is printed? Is this possible with String objects? Should I just use a character array?

Use a null terminated char array.

String objects are evil. String objects in interrupts? That's just plain satanic!

Don't use them, especially not in an ISR. Stick to C strings (char arrays) and you'll have less problems with your code. Also you won't be ridiculed for using Strings.

I use std::string objects in C++ on a PC, but I have never, and will never, use Strings on a microcontroller.

As a long time Assembly and C programmer I keep trying to drink the Object Oriented Koolaid but I keep choking on it... :stuck_out_tongue:

If your message needs to contain dynamic data, print it to a volatile global char array.

If it doesn't, just use a char pointer and assign it to a suitable string literal.

Remember that, since char arrays and char pointers are bigger than a byte, accesses to them are not atomic and you would need to suspend interrupts in the main context when you access them.

It would be quite a lot simpler if you can reduce your debug messages to a one-byte value, for example by defining a set of enumerated values that index into an array of message strings so that your main context code can do the lookup itself.

All you ever need to do in a case like this is to note that the interrupt has happened. Setup your out in the main code not in the isr.

Mark