std.file.read returns void[] why?

Steven Schveighoffer schveiguy at yahoo.com
Thu Apr 17 07:56:05 PDT 2014


On Thu, 17 Apr 2014 10:05:49 -0400, Regan Heath <regan at netmail.co.nz>  
wrote:

> On Thu, 17 Apr 2014 13:59:20 +0100, Steven Schveighoffer  
> <schveiguy at yahoo.com> wrote:
>> It was never possible. You must explicitly cast to void[].
>
> to -> from?

Yes, sorry :)

>> void[] makes actually little sense as the result of whole-file read  
>> that allocates. byte[] is at least usable and more accurate. In fact,  
>> it's a little dangerous to use void[], since you could assign  
>> pointer-containing values to the void[] and it should be marked as  
>> NOSCAN (no pointers inside file data).
>
> I see what you're saying, byte[] is what *is* allocated.. but my point  
> is that it's not what those bytes actually represent.
>
> Are you saying void[] *is* currently marked NOSCAN?

No, I mean the return value from read, since it's newly allocated general  
data, should be marked NOSCAN.

Casting the type does not change how the block is marked, only the  
allocation type makes that distinction. When you *allocate* a void[]  
buffer, it's marked no scan. But when you allocate a byte[] buffer and  
implicitly cast it to void[], it's not marked NOSCAN.

TL;DR, IMO read should return byte[].

-Steve


More information about the Digitalmars-d-learn mailing list