Two possibilities of fixing format problem, which is better?
berni44
dlang at d-ecke.de
Tue Oct 22 16:34:52 UTC 2019
On Monday, 21 October 2019 at 07:18:09 UTC, berni44 wrote:
> On Sunday, 20 October 2019 at 23:15:28 UTC, rikki cattermole
> wrote:
>> What does printf do?
>
> b) :-) Thanks.
Unfortunately, meanwhile I learned, that there are various
implementations of printf with different behaviour. So it doesn't
really answer my original question.
Here an example:
import std.stdio;
int[] a = [1,23,-456];
writeln(format("%20s",a));
writeln(format("[%(%20s%|, %)]",a));
produces:
[ 1, 23, -456]
[ 1, 23, -456]
but IMHO the first line should be:
[1, 23, -456]
This is in accordance with the current Phobos spec and some
printf spec I found in the internet. Should this be corrected?
Similar:
import std.stdio;
char[] a = ['a','b','c'];
writeln(format("%20s",a));
writeln(format("[%(%20s%|, %)]",a));
produces:
abc
['a', 'b', 'c']
And:
import std.stdio;
String[] a = ["a","b","c"];
writeln(format("%20s",a));
writeln(format("[%(%20s%|, %)]",a));
produces:
["a", "b", "c"]
["a", "b", "c"]
So my question remains: What is considered correct behaviour here?
More information about the Digitalmars-d
mailing list