casting and arrays..
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Sun Mar 11 01:37:08 PST 2007
Daniel Keep wrote:
>
> Incidentally, I never knew that you could safely cast arrays of one type
> to another! Yet another thing I didn't know about D :P
I never saw anyone claim it was _safe_, just that it was _possible_ ;)...
Casting arrays is about as safe as pointer casting (which is actually
pretty much what you're doing), which is to say it isn't safe unless
you're very careful ;).
For example, if the type you're casting to an array of contains any
pointers or class references, you've usually got a problem unless you're
sure those are valid (reading pointers from anything that wasn't always
in memory is a bad idea, for example; so no reading pointers from file
or socket connections).
The only thing that's safer about array casting is that the length of
the data is taken into account, so you won't as easily be accessing
invalid memory. Which I'd say is more of a property of arrays vs
pointers, instead of array casting vs pointer casting.
More information about the Digitalmars-d-learn
mailing list