2 days ago

On Wednesday, 14 May 2025 at 11:38:59 UTC, Nick Treleaven wrote:

>

On Wednesday, 14 May 2025 at 03:36:40 UTC, Jonathan M Davis wrote:

>

to!string definitely deals with null-terminated strings, or it wouldn't work at all. It's not the kind of thing that would work by accident.

I don't think it's good API design:

>

Pointer to string conversions convert the pointer to a size_t value. If pointer is char*, treat it as C-style strings. In that case, this function is @system.

So to!string is bad for generic code.

Yup. to!T is like a swiss army knife - it can do everything, but it is never as good as a tool dedicated to a specific purpose.

So, to!T is good if T can be anything, but if you know beforehand that T will always be string, use something else like ptr.fromStringz.idup

23 hours ago

On Wednesday, 14 May 2025 at 11:38:59 UTC, Nick Treleaven wrote:

>

So to!string is bad for generic code. Want to represent the address of a byte* as hex in a string, fine. Oh now the pointer's element type is char - wait, why isn't the result hex any more?

try to!(string,void*)?

20 hours ago

On Friday, 16 May 2025 at 09:42:20 UTC, Kagamin wrote:

>

On Wednesday, 14 May 2025 at 11:38:59 UTC, Nick Treleaven wrote:

>

So to!string is bad for generic code. Want to represent the address of a byte* as hex in a string, fine. Oh now the pointer's element type is char - wait, why isn't the result hex any more?

try to!(string,void*)?

This works, but it relies on an undocumented template parameter AFAICS:

    char c;
    alias tos = to!string;
    tos!(void*)(&c).writeln;
1 2
Next ›   Last »