Kill implicit joining of adjacent strings
Rainer Deyke
rainerd at eldwood.com
Thu Nov 11 12:05:08 PST 2010
On 11/11/2010 06:06, Michel Fortin wrote:
> On 2010-11-10 23:51:38 -0500, Rainer Deyke <rainerd at eldwood.com> said:
>
>> As it turns out, the joining of adjacent strings is a critical feature.
>> Consider the following:
>> f("a" "b");
>> f("a" ~ "b");
>> These are /not/ equivalent. In the former cases, 'f' receives a string
>> literal as argument, which means that the string is guaranteed to be
>> zero terminated. In the latter case, 'f' receives an expression (which
>> can be evaluated at compile time) as argument, so the string may not be
>> zero terminated. This is a critical difference if 'f' is a (wrapper
>> around a) C function.
>
> You worry too much. With 'f' a wrapper around a C function that takes a
> const(char)* argument, if the argument is not a literal string then it
> won't compile. Only string literals are implicitly convertible to
> const(char)*, not 'string' variables.
You just restated the problem. There needs to be a way to break up
string literals while still treating them as a single string literal
that is convertible to 'const(char)*'. You could overload binary '~'
for this, but I think this may be confusing.
--
Rainer Deyke - rainerd at eldwood.com
More information about the Digitalmars-d
mailing list