string to char array?
Kyoji Klyden via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jun 5 10:27:17 PDT 2015
On Thursday, 4 June 2015 at 22:28:50 UTC, anonymous wrote:
>
> Generally, a `char**` is a pointer to a pointer to a char.
> There may be more pointers to chars behind the pointed-to one.
> And there may be more chars behind the pointed-to ones. You
> can't know just from the type. You have to read the
> documentation of the involved functions for the specifics.
>
Alright, kinda a bummer I need to do some digging for each
third-party function I use, but oh well.
This probably comes from lack of experience but I can't really
imagine ever writing something that is more than one or two
pointers long.. like wouldn't that call for a redesign of
whatever library was being written?
On Thursday, 4 June 2015 at 22:33:13 UTC, Ali Çehreli wrote:
>
> Yep, "C's biggest mistake":
>
>
> http://www.drdobbs.com/architecture-and-design/cs-biggest-mistake/228701625
>
> Ali
Thx for the link. I think I read this a couple years ago, but at
the time had no idea what Walter was talking about. (probably
because I was only using Python back when I read it)
>> Also does D primarily use explicit length field strings?
>
> I'm not sure if I understand you right, but yes, D arrays carry
> their length. And D `string`s are arrays. You should encounter
> things like `char**` pretty much only when talking to C code.
>
> By the way, there are subtly different meanings of "array" and
> "string" which I hope you're aware of, but just to be sure:
> "array" can refer to D array types, i.e. a pointer-length pair,
> e.g. char[]. Or it can refer to the general concept of a
> contiguous sequence of elements in memory.
> And as a special case, "string" can refer to D's `string` type,
> which is an alias for `immutable(char)[]`. Or it can refer to a
> contiguous sequence of characters in memory.
> And when ketmar writes: "it's a pointer to array of pointers to
> first chars of strings", then "array" and "string" are meant in
> the generic way, not in the D-specific way.
Yeah that's what I meant. I just got the phrasing for that out of
a compiler book I have.
I now see alot of my confusion is coming from me poorly assuming
C, D, and sometimes C++ are functioning/handling data the same
way. Clearly there's more to it than simply
ProgrammingLanguage->IR->MachineCode (obviously to horribly
simplify it).
So how does D store arrays in memory then?
I know you already explained this part, but..
Does the slice's pointer point to the slice's position in memory?
Then if an array isn't sequential, is it atleast a sequence of
pointers to the slice structs (& those are just in whatever spot
in memory they could get?)
There's a slice for each array index..right? Or is it only for
the first element?
Thanks!
More information about the Digitalmars-d-learn
mailing list