S
Steve Pope
The first of the following functions compiles, the second gives what
I think is a spurious error:
"cannot convert `const char[5]' to `char *' in assignment".
void foo(int m) {
char *str;
if (m < 4) str = "%01x";
else if (m < 9) str = "%02x";
else str = "%03x";
}
void foo(int m) {
char *str;
str = m < 4 ? "%01x" : m < 9 ? "%02x" : "%03x";
}
Any idea why gcc doesn't like the second version? If I compile
it as a C file instead of C++, it works fine.
Steve
I think is a spurious error:
"cannot convert `const char[5]' to `char *' in assignment".
void foo(int m) {
char *str;
if (m < 4) str = "%01x";
else if (m < 9) str = "%02x";
else str = "%03x";
}
void foo(int m) {
char *str;
str = m < 4 ? "%01x" : m < 9 ? "%02x" : "%03x";
}
Any idea why gcc doesn't like the second version? If I compile
it as a C file instead of C++, it works fine.
Steve