[Issue 4572] std.file.read return type
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Aug 4 06:02:22 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4572
--- Comment #7 from Steven Schveighoffer <schveiguy at yahoo.com> 2010-08-04 06:02:21 PDT ---
(In reply to comment #6)
> Thank you for your answer Steven.
>
> > then, you must cast your data to a ubyte[]. But void[] can be implicitly cast
> > to from anything, so void[] wins here.
>
> If you compile this program with dmd 2.047:
>
> void main() {
> auto v = new void[10];
> ubyte a1, a2;
> a1 = v;
> v = a2;
> }
>
>
> It produces the errors:
> test.d(4): Error: cannot implicitly convert expression (v) of type void[] to
> ubyte
> test.d(5): Error: cannot implicitly convert expression (a2) of type ubyte to
> void[]
Yes, D does not convert non-arrays to void[]. You can do something like this:
v = (&a2)[0..1];
which is typically what is done. ubyte[] provides no automatic conversion from
anything, including other array types.
> > But we can forgo all this stuff if we add a template parameter to read, so you
> > can specify exactly the type you want. If you know your file is a bunch of
> > int's, you could do:
> > std.file.read!(int)();
>
> It seems a good idea. So I presume std.file.read!(int[])(); reads a matrix.
Well, I would assume it would return an int[][], which probably would mean
nothing since arrays are pointer/length values, and any pointer/length values
read from a file would be bogus. I'd say read should reject reading elements
that have references in them.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list