How to compare two volatile Strings in Arduino IDE?

I have two global volatile Strings (I change them in interrupt function):
volatile String x1 = "abc", x2 = "abc"; // "abc" is an example
And I try to compare them (in loop() function):
if (x1 == x2) {
... // some code
}
else {
... // some code
}
And a comiler throws:
exit status 1
binding 'volatile String' to reference of type 'const String&' discards qualifiers

I also tried:
if (x1.equals(x2)) {
...
}
else {
...
}
And the compiler throws the same message.
How can I compare them?
*Sorry, I'm not British or American so I don't know English well. Please forgive me for some grammatical errors I may have made.

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).

When using Cstrings you must use strcmp() to compare values rather than ==

...R

You're going to always have that problem with String as none of its methods are defined for 'volatile' parameters.

In addition to switching to c-strings, you'll need to protect access to them in non-ISR code by using critical sections as it will not be atomic:

volatile char x1[10] = "123";
volatile char x2[10] = "456";

void setup() {
  char x1Local[10], x2Local[10];
  Serial.begin(115200);
  delay(1000);

  noInterrupts();
  strcpy(x1Local, (char *)x1);
  strcpy(x2Local, (char *)x2);
  interrupts();

  if (strcmp(x1Local, x2Local) == 0) {
    Serial.println("Equal");
  } else {
    Serial.println("Not Equal");
  }
}

void loop() {
}

Actually, it's not clear to me how the code I posted above will compile once the 'volatile' specifier is cast off. You might be better off implementing the strcpy yourself as below. Note that this is minimalist code without proper checking for writing beyond the array's end. You'll need to be more careful.

volatile char x1[10] = "123";
volatile char x2[10] = "456";

void setup() {
  char x1Local[10], x2Local[10];
  volatile char *vPtr;
  char *lPtr;
  Serial.begin(115200);
  delay(1000);

  noInterrupts();
  vPtr = x1 - 1;
  lPtr = x1Local - 1;
  do {
    *(++lPtr) = *(++vPtr);
  } while (*lPtr);

  vPtr = x2 - 1;
  lPtr = x2Local - 1;
  do {
    *(++lPtr) = *(++vPtr);
  } while (*lPtr);
  interrupts();

  if (strcmp(x1Local, x2Local) == 0) {
    Serial.println("Equal");
  } else {
    Serial.println("Not Equal");
  }
}

void loop() {
}

evjeny23:
I have two global volatile Strings (I change them in interrupt function):

volatile String x1 = "abc", x2 = "abc"; // "abc" is an example

And I try to compare them (in loop() function):
if (x1 == x2) {
   ... // some code
}
else {
   ... // some code
}



And a comiler throws:
exit status 1
binding 'volatile String' to reference of type 'const String&' discards qualifiers

As with all volatile variables larger than one byte you are supposed to make copies with interrupts disabled and use the non-volatile copies for comparisons and calculations.

volatile String x1 = "abc", x2 = "abc"; // "abc" is an example
void loop() {
    noInterrupts();
    const String local_x1 = x1;
    const String local_x2 = x2;
    interrupts();
 .  if (local_x1 == local_x2) {
       ... // some code
    }
    else {
       ... // some code
    }

johnwasser:
As with all volatile variables larger than one byte you are supposed to make copies with interrupts disabled and use the non-volatile copies for comparisons and calculations.

volatile String x1 = "abc", x2 = "abc"; // "abc" is an example

void loop() {
   noInterrupts();
   const String local_x1 = x1;
   const String local_x2 = x2;
   interrupts();
.  if (local_x1 == local_x2) {
      ... // some code
   }
   else {
      ... // some code
   }

When I try to do this I get this message:
exit status 1
no matching function for call to 'String(volatile String&)'

As I stated in Reply #2, the String class has no methods that specify 'volatile' objects. That includes not having an overloaded assignment operator that accepts a reference to a volatile String object.

gfvalvo:
As I stated in Reply #2, the String class has no methods that specify 'volatile' objects. That includes not having an overloaded assignment operator that accepts a reference to a volatile String object.

Wow. Can't even cast a 'volatile String' to 'String' because "error: no matching function for call to 'String(volatile String&)'". Looks like it is impossible to use a 'volatile' String. I tried casting. I tried a 'union' of String and volatile String. In all cases the 'volatile String' caused compile errors.
Looks like the only way might be to add a bunch of 'volatile' functions to the String data type.
I'd recommend abandoning using String variables in any ISR.