Is implicit string literal concatenation a good thing?
BCS
none at anon.com
Sun Feb 22 13:12:14 PST 2009
Hello Jarrett,
> On Sun, Feb 22, 2009 at 12:51 PM, Bill Baxter <wbaxter at gmail.com>
> wrote:
>
>> I use this feature pretty frequently to break up long strings. I
>> think I didn't use ~ for that because it makes me think an allocation
>> might happen when it doesn't need to.
>>
>> But after seeing the discussion here I'd be happy to switch to using
>> "a"~"b" as long as it's guaranteed by the language that such strings
>> will be concatenated at compile time. (I think the is the case now,
>> right?)
>>
> Of course, it does it as a matter of constant folding, just like 3 +
> 4.
>
IIRC DMD doesn't always do the constant folding (Decent has a post processed
view that shows this in some cases) For instance, IIRC it only does left
most so this:
char[] foo = "foo";
char[] bar = foo ~ "bar" ~ "baz"
doesn't get folded. And even if DMD were to start doing that one, there is
no requirement that another compiler also do it.
More information about the Digitalmars-d
mailing list