Is implicit string literal concatenation a good thing?
Jarrett Billingsley
jarrett.billingsley at gmail.com
Sun Feb 22 20:51:07 PST 2009
On Sun, Feb 22, 2009 at 9:29 PM, bearophile <bearophileHUGS at lycos.com> wrote:
> Are you saying that the concat operation of
> "123" ~ "456"
> has a different (invisible) "operator" precedence of:
> "123" "456" ?
> If this is true, then the ~ isn't a fully drop-in replacement for the automatic concat of strings as done in C...
Currently that's the case. But it's simply unspecified in the
language specification, and there's no reason why the compiler can't
turn:
a = foo ~ "bar" ~ "baz";
into:
a = foo ~ "barbaz";
FWIW the MiniD compiler does this already. It's just that DMD
currently does concatenation constant folding in a simple manner that
makes this kind of folding "invisible" to it.
But when all the operands of the concatenations are strings - like
when building up strings to be mixed-in, or in static/const variable
initializers - then everything will obviously be folded at compile
time.
More information about the Digitalmars-d
mailing list