Change representation of dynamic arrays?
Oskar Linde
oskar.lindeREM at OVEgmail.com
Sat Oct 20 00:13:49 PDT 2007
Janice Caron wrote:
> 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.
I guess there could be a warning (or error) passing a D array as a C
vararg argument.
> 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.
I am well aware of that, and I dont blame anyone for using the idiom. I
merely blame the recommendation. ;)
> 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.
Printf is standardized. That is not the problem. The problem is that the
above idiom is a hack relying on a specific stack layout when passing
vararg arguments to C functions.
--
Oskar
More information about the Digitalmars-d
mailing list