I have a very simple program which just outputs indefinitely a const pointer pointing to a const volatile char; it goes like this:
const volatile char* const str = "ABCDEFGHIJKL";
while(true) {
cout << '\r' << str;
}
The problem is that when running this program, the output is 1. There is a way to get around this, which is outputting const_cast<char*>(str) instead of str.
But if I do const_cast<volatile char*>(str) the output is 1, just like before the cast, so I'm guessing the 1 output is caused by the volatile keyword, which is strange because I thought that volatile only makes the compiler avoid optimizations in that variable, which shouldn't change the value of it.
My question, therefore, is how in the world did that 1 came as the output.
NOTE:
I've tried compiling it with GCC in Ubuntu 16.04, and with MinGW in Windows 7, so the compiler is not the problem(I guess).