Re: Calling C functions that modify a string

2023-06-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/15/23 2:21 PM, bachmeier wrote: On Thursday, 15 June 2023 at 15:53:57 UTC, Steven Schveighoffer wrote: On 6/15/23 10:04 AM, Jonathan M Davis wrote: On Thursday, June 15, 2023 7:18:06 AM MDT Steven Schveighoffer via Digitalmars-d-learn wrote: But in general, if you want a mutable character

Re: Calling C functions that modify a string

2023-06-15 Thread bachmeier via Digitalmars-d-learn
On Thursday, 15 June 2023 at 15:53:57 UTC, Steven Schveighoffer wrote: On 6/15/23 10:04 AM, Jonathan M Davis wrote: On Thursday, June 15, 2023 7:18:06 AM MDT Steven Schveighoffer via Digitalmars-d-learn wrote: But in general, if you want a mutable character array that's zero terminated, you ne

Re: Calling C functions that modify a string

2023-06-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/15/23 10:04 AM, Jonathan M Davis wrote: On Thursday, June 15, 2023 7:18:06 AM MDT Steven Schveighoffer via Digitalmars-d-learn wrote: But in general, if you want a mutable character array that's zero terminated, you need to make a copy with a zero terminator, but type it as mutable. I'm sur

Re: Calling C functions that modify a string

2023-06-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, June 15, 2023 7:18:06 AM MDT Steven Schveighoffer via Digitalmars-d-learn wrote: > But in general, if you want a mutable character array that's zero > terminated, you need to make a copy with a zero terminator, but type it > as mutable. I'm surprised there isn't a way to do this easil

Re: Calling C functions that modify a string

2023-06-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/15/23 9:18 AM, Steven Schveighoffer wrote: So interestingly enough, toStringz is pure, and returns an unrelated type, so you shouldn't need to cast. However, for some reason, it does require a cast. That seems like a bug to me. Oh wait, a pure function can return immutable data that isn't

Re: Calling C functions that modify a string

2023-06-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/14/23 11:29 PM, Pat Maddox wrote: Hi there, I want to call a C function that upcases a string. I have something working, I just want to check in here to see if there's a better approach that I'm missing. I ask because `std.string.toStringZ()` returns an `immutable char *`. As far as I ca

Calling C functions that modify a string

2023-06-14 Thread Pat Maddox via Digitalmars-d-learn
Hi there, I want to call a C function that upcases a string. I have something working, I just want to check in here to see if there's a better approach that I'm missing. I ask because `std.string.toStringZ()` returns an `immutable char *`. As far as I can tell, I have two options: 1. Make the