Make printf safe
Paul Backus
snarwin at gmail.com
Tue Jul 16 15:45:45 UTC 2024
On Tuesday, 16 July 2024 at 01:22:14 UTC, Walter Bright wrote:
>> I suppose we could have the compiler insert a bounds check, in
>> addition to all of the other rewrites, but at this point, it
>> feels like we're not really calling printf at all; we're
>> calling some other formatted-output function that's stolen
>> printf's identity.
>
> Wrapping APIs with a better interface is what we do all the
> time :-/
Of course. What I find objectionable in this case is that (a) the
better interface is implemented using a bunch of
compiler-internal rewrites, rather than normal D code; and (b) it
shadows the existing C printf function rather than existing
alongside it.
If we need a safer printf for DMD that doesn't carry all the
bloat and baggage of Phobos's writef, then by all means, let's
write one. But let's write it in D and put it in a normal D
module, instead of sneaking around and redefining printf behind
our users' backs.
More information about the dip.ideas
mailing list