[phobos] returning void[] from std.file.read()

Jonathan M Davis jmdavisProg at gmx.com
Sat Sep 25 21:32:41 PDT 2010


On Saturday 25 September 2010 19:46:37 Robert Jacques wrote:
> On Sat, 25 Sep 2010 17:17:58 -0400, Andrei Alexandrescu
> 
> <andrei at erdani.com> wrote:
> > This has come up in http://d.puremagic.com/issues/show_bug.cgi?id=1482.
> > Should std.file.read() return void[] or ubyte[]? There's one matter with
> > assuming that void[] may contain pointers (which is not the case for
> > something read from a file), so possibly ubyte[] is a more accurate type
> > for describng raw bytes.
> > 
> > What are the pros and cons of returning void[] vs. ubyte[]?
> > 
> > 
> > Andrei
> 
> Pro:
> Well, the very first thing I always do with std.file.read is to cast the
> data to the type I'm working with. So:
> 
> auto data = cast(float[])read("my_data.raw");
> 
> vs.
> 
> auto data = cast(float[])(cast(void[])read("my_data.raw"));
> 
> Having read return ubyte would mean adding an extra cast in several use
> cases

Why would you need two casts? I would expect that one would suffice without the 
need to cast to void[] in between.

- Jonathan M Davis


More information about the phobos mailing list