www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - 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.
Jul 25 2005