DIP 1027---String Interpolation---Community Review Round 1

Patrick Schluter Patrick.Schluter at bbox.fr
Wed Dec 11 15:37:58 UTC 2019


On Wednesday, 11 December 2019 at 09:52:21 UTC, Mike Parker wrote:

The transformation is WRONG!
'%%', a '%' is written to the output string.

it must be
'%%', a '%%' is written to the output string or else you will 
have problems

Example. If I have following expression

writefln(i"I ate %{d}apples and %{d}bananas totalling 
%{d}(100*apples/bananas) %%fruit\n");

it would be lowered to

writefln("I ate %d and %d totalling %d %fruit\n", apples, 
bananas, (100*apples/bananas));

The %% being transformed to a simple %, we now have a %f with no 
parameter => compilation error or worse undefined behaviour in 
case of printf.

I would have to write

writefln(i"I ate %{d}apples and %{d}bananas totalling 
%{d}(100*apples/bananas) %%%%fruit\n");

which is not good.

So '%%' have to be untouched by the lowering



More information about the Digitalmars-d mailing list