www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24086] New: No output or failed function call

https://issues.dlang.org/show_bug.cgi?id=24086

          Issue ID: 24086
           Summary: No output or failed function call
           Product: D
           Version: D2
          Hardware: x86
               URL: http://dlang.org/
                OS: All
            Status: NEW
          Severity: major
          Priority: P3
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: apz28 hotmail.com

import std.stdio;
import std.bitmanip : bigEndianToNative, nativeToBigEndian;

nothrow  safe:

struct X(int N)
{
 nogc nothrow  safe:

   enum HALFSize = N / 2;
   alias HALF = makeHALF!HALFSize;

   version (LittleEndian)
    {
        HALF lo;
        HALF hi;
    }
    else
    {
        HALF hi;
        HALF lo;
    }    

    this(scope const(ubyte)[] bigEndianBytes) pure
    {        
    }

    ubyte[] toBigEndianBytes(return ubyte[] bytes) const
    in
    {
        assert(bytes.length == N);
    }
    do
    {
        debug writeln("toBigEndianBytes: ", Bytes);

        static if (N <= 4)
        {
            bytes[0..HALFSize] = nativeToBigEndian(hi);
            bytes[HALFSize..N] = nativeToBigEndian(lo);
        }
        else
        {
            hi.toBigEndianBytes(bytes[0..HALFSize]);
            lo.toBigEndianBytes(bytes[HALFSize..N]);
        }
        return bytes;
    }    
}

template makeHALF(int N)
{
    static if (N >= 4)
        alias makeHALF = X!N;
    else static if (N == 2)
        alias makeHALF = ushort;
    else static if (N == 1)
        alias makeHALF = ubyte;
    else
        static assert(0, "Unsupport makeHALF");
}

alias x4 = X!4;
alias x8 = X!8;

static immutable x4[2] x4s = [
    x4([1]),
    x4([2]),
];

static immutable x8[2] x8s = [
    x8([3]),
    x8([4]),
];

void main()
{
    ubyte[4] b4;
        foreach (i, e; x4s)
    {
        debug writeln("x4s: [", i, "] ", e.toBigEndianBytes(b4));
    }

    ubyte[8] b8;
        foreach (i, e; x8s)
    {
        debug writeln("x8s: [", i, "] ", e.toBigEndianBytes(b8));
    }    
}

--
Aug 14 2023