About void[] and asockets

Jolly James via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Feb 22 09:06:51 PST 2017


On Wednesday, 22 February 2017 at 17:01:11 UTC, Adam D. Ruppe 
wrote:
> On Wednesday, 22 February 2017 at 16:55:03 UTC, Jolly James 
> wrote:
>> Well, what are these void-arrays for real? I mean, they 
>> contain data what does not make them really void, does it?
>
> They represent an array of anything; the user can pass ubyte[] 
> to it, or int[] to it, or char[] to it, or anything else (even 
> string if it is in void[] or const void[]).
>
>> And how to I get received data out of Data.content[]?
>> How to use TcpConnection.send()? E.g. for sending a string?
>
> Cast it to `const(ubyte)[]` then use it as a bag of bytes. 
> That's almost always what you want to do inside.
>
> The function signature uses `in void[]` instead of `ubyte[]` 
> because void will accept strings and other stuff too, whereas 
> ubyte specifically requires it to be typed as bye.
>
> You want to use it INTERNALLY as bytes, but the external 
> interface can accept almost anything.

Thank you very much!
Now it makes sense and I understand.


More information about the Digitalmars-d-learn mailing list