Sockets between D and C(++) app

Alexandre L. alex.cs00 at mail.com
Tue Apr 1 17:52:48 PDT 2014


On Wednesday, 2 April 2014 at 00:34:08 UTC, bearophile wrote:
>> 		char[] rep = "regan\0".dup;
>> 		
>> 		s.send(cast(ubyte[])rep);
>
> casts are dangerous, because they silently assume you know what 
> you are doing. As first try I suggest you to remove every 
> cast() from your D program, and replace them with to!() or 
> other functions like toStringz. Sometimes this is not the most 
> efficient thing to do, but it's safer, so it's better when you 
> start to learn D.
>
> Bye,
> bearophile

Thanks for your reply. As for cast, I seems not to have any 
option, because to! doesn't work as I would expect it. It would 
return me an array of numbers, instead of a string; So I kept the 
cast here, since I certainly know what it's doing -for now-.

I generally use immutables, you caught me, here :-). As of main 
and return, I was not aware we could just ignore them if we 
didn't need them. I love explicit programming.

However, I'm still stuck with toStringz(). Since it returns an 
immutable(char[]), I can't find how to pass it to Socket.send(), 
and I do not seem to be able to cast away the immutable :-s

Alexandre


More information about the Digitalmars-d-learn mailing list