March 11, 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.
March 11, 2007
"Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message news:et00eg$66h$1@digitalmars.com...
> "Chris Warwick" <sp@m.me.not> wrote in message news:esvnvu$2ku8$1@digitalmars.com...
>>
>> Well i cant realy do that cause im reading a binary file in, and then i want to parse it, extract structs and various types here and there.
>
> I wouldn't really recommend std.file.read for anything more than reading in the simplest of files.  Use std.stream.File or BufferedFile for reading in complex files.  You can then read in a struct with .readExact.

Note to self ... RTFM

;-)


March 11, 2007
"Chris Warwick" <sp@m.me.not> wrote in message news:et0s2n$1no1$1@digitalmars.com...
>
> Note to self ... RTFM
>

Hehe :)  Though when I first started using D, I thought std.file would be the best place for file IO too!  Maybe I don't think like a C++ programmer, where file IO should be done with streams..


1 2
Next ›   Last »