July 25, 2005 Literal Strings and tertiaries | ||||
|---|---|---|---|---|
| ||||
I am a little confused. Am using DMC 8.44 (beta) which in which literal strings are taken as constant. Except when they aren't...
Given the following
void foo (char *);
main ()
{ char *p = "hello";
int f= 1;
foo("hello");
foo(p);
foo (f ? "a" : "b");
foo (f ? p : "b");
}
foo (f ? "a" : "b");
^
test.cpp(9) : Error: need explicit cast for function parameter 1 to get
from: char const *
to : char *
foo (f ? p : "b");
^
test.cpp(10) : Error: need explicit cast for function parameter 1 to get
from: char const *
to : char *
--- errorlevel 1
It seems to me that the first of the function calls should be an error. Except - I guess - that this would break so much existing code as to be useless. But then if we are to allow that, then why not the tertiaries?
Cheers,
John.
| ||||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply