Hrdcoded

aerto cvsae at gmx.com
Mon Jan 16 15:49:27 UTC 2023


On Monday, 16 January 2023 at 15:35:38 UTC, Dennis wrote:
> On Monday, 16 January 2023 at 15:16:46 UTC, aerto wrote:
>> The above code doesn't work.
>
> What doesn't work?
>
> Can you also give the definitions of the variables and 
> functions involved?

     class iv{
       private byte[] buffer;
       private ulong writePos;
       private ulong readPos;

       this(){}

       void write(T)(T value) if (is(T == uint)){
         buffer ~= nativeToLittleEndian!uint(value);
         writePos += uint.sizeof;
       }

       uint readUint()
       {
         assert(readPos == 0);
         uint value = 
littleEndianToNative!uint(cast(ubyte[uint.sizeof])buffer[readPos..readPos+uint.sizeof]);
         readPos += uint.sizeof;
         return value;
       }

       uint readUint_test()
       {
         assert(readPos == 0);
         uint value = 
littleEndianToNative!uint(cast(ubyte[uint.sizeof])buffer[0..0+uint.sizeof]);
         readPos += uint.sizeof;
         return value;
       }
     }


void main()
{

       auto cc = new iv();

       uint ptr = 1000000;

       cc.write(ptr);
       writeln(cc.readUint()); //not works
       writeln(cc.readUint_test()); // works

}

The readUint_test its working while the readUint not.


More information about the Digitalmars-d mailing list