Change representation of dynamic arrays?

Janice Caron caron800 at googlemail.com
Sat Oct 20 00:00:59 PDT 2007


On 10/20/07, Oskar Linde <oskar.lindeREM at ovegmail.com> wrote:
> > 1) Passing dynamic arrays to printf as in:
> >
> >     printf("my string is %*.s\n", str);
>
> I'm glad that breaks. That code was never portable anyway

I'd be happy for it to break if the break could be detected at compile
time (or even at runtime with an assert). I'm not terrifically happy
that source code that previously generated code that ran just fine
would now generate code that will simply crash with no explanation.

You have to remember that there was once a time when writef() and
family did not exist, and that printf("%.*s") was the /recommended/
way of doing things, documented as such on the Digital Mars site. So
you cannot blame anyone for using that idiom, say, three or four years
ago.

As for not portable, I'm surprised at that. I thought the C printf()
function was fairly standardised? Ah well, it doesn't matter. I'm sure
everyone here agrees that D folk should not use printf anyway, now
that we've got better things.

I'd be all in favor making any use of printf a compile error - say by
making a global function which takes no parameters (forcing coders to
explicity qualify the function name if they wanted to C printf). Note
that this reasoning also applies to vprintf, fprintf, vfprintf,
sprintf, snprintf, etc., etc...



More information about the Digitalmars-d mailing list