std.stream.EndianStream ...

Ben Hinkle bhinkle at mathworks.com
Thu Feb 8 07:11:39 PST 2007


"torhu" <fake at address.dude> wrote in message 
news:eqeff9$22i3$1 at digitaldaemon.com...
> nescire wrote:
>> EndianStream es = new EndianStream( new MemoryStream() );
>> ubyte b;
>> es.read( b );
>>
>> dmd gives the error:
>>
>> function std.stream.EndianStream.read called with argument types:
>> (ubyte)
>> matches both:
>> std.stream.EndianStream.read(short)
>> and:
>> std.stream.EndianStream.read(dchar)
>>
>> Which seems to suggest the EndianStream class does not have a void 
>> read( out ubyte ) method, even though it should inherit it from 
>> FilterStream.
>
> It's hard to find anything about this in the docs.  But it seems overloads 
> are not inherited by default, which is the same behavior as in C++. 
> EndianStream redefine most of the read() overloads, but not the byte and 
> ubyte versions.  The read() methods does the actual byteswapping, which 
> wouldn't work on single-byte reads.  So this is done on purpose.
>
> You would do 'alias SuperClass.method method;' to pull in 'method()' 
> overloads from SuperClass.

yeah, looks like that should be added to EndianStream.

>> And the following code compiles:
>>
>> EndianStream es = new EndianStream( new MemoryStream() );
>> ubyte b;
>> (cast(InputStream) es).read( b );
>>
>>
>> Could someone explain? Am I missing something obvious, or is it a 
>> compiler bug?
>
>
> I'm guessing this makes it call Stream's version of read(ubyte), which 
> will give the wrong result.

Why is that the wrong result? EndianStream only swaps when reading 
multi-byte data since there's nothing to swap with a single byte. 




More information about the Digitalmars-d-learn mailing list