Make printf safe
Quirin Schroll
qs.il.paperinik at gmail.com
Wed Jul 17 10:25:48 UTC 2024
On Wednesday, 17 July 2024 at 09:20:23 UTC, Nick Treleaven wrote:
> On Wednesday, 17 July 2024 at 08:58:56 UTC, IchorDev wrote:
>> On Saturday, 13 July 2024 at 20:39:32 UTC, Walter Bright wrote:
>>> The idea is printf is already largely safe:
>>> [...]
>>
>> [`@safe` functions cannot perform pointer
>> arithmetic](https://dlang.org/spec/function.html#safe-functions), but `printf` does because it indexes a `char*` (its first parameter).
>
> The idea is to make certain calls of `printf` safe when the
> first argument is a string literal:
> ```
> char[] s;
> printf("%s\n", s);
> ```
> See https://forum.dlang.org/post/v775k1$1tmj$1@digitalmars.com.
I fail to see why there can’t be a `dprintf` that works like
`printf` except that for `*.s` bound to a `const(char)[]` object,
it decomposes it properly into its length and pointer component.
Or, even better, use a different specifier, e.g. `%D`.
More information about the dip.ideas
mailing list