Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

static const char[?

const static
0
Posted

static const char[?

0

in C++. This allows overloading to occur properly with a routine accepting say a const char *. It also works with legacy situations because C++ also provides for a conversion so that when a const char * is not the target, it will also still allow legacy assignments to char *s. The conversion does not change the writeability of the literal though. • A given implementation may always allow extensions, so a given implementation, or even mode of an implementation perhaps controlled by a command line switch, may allow string literal writeability. • There is a transformation possible which removes the undefined behavior: Name the string literal: #include int main() { char comeau[] = “comeau”; /* Name it, now it’s writeable, and unique. You may or may want it to also be static or const which may or may not require other code changes. */ char *p = comeau; p[0] = ‘C’; /* Ok */ printf(“p=’%s’\n”, p); return 0; } When possible, you can also declare the original pointer as a const char *

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.