Exemplo n.º 1
0
    unsafe public static int Main()
    {
        UnalignedValue v = new UnalignedValue();

        v.d = 0x0FFFFFFFFFFFFFF0;
        v.c = 0x77777777;
        v.b = 0x3333;
        v.a = 0x11;

        long sum = v.a + v.b + v.c + v.d;

        if (sum != (BitConverter.IsLittleEndian ? 0x0FFFFFFFEEEE9944 : 0x11337778113388AB))
        {
            Console.WriteLine("Unexpected long value:" + sum.ToString());
            Environment.Exit(1);
        }

        SmallValue t;

        t    = v.x;
        t.x += 1.0;
        v.x  = t;

        byte *  pa = (byte *)&v.a;
        ushort *pb = (ushort *)&v.b;
        uint *  pc = (uint *)&v.c;
        ulong * pd = (ulong *)&v.d;

        *pd = 0x0EEEEEEEEEEEEEE0;
        *pc = 0x66666666;
        *pb = 0x2222;
        *pa = 0x00;

        ulong usum = (ulong)*pa + (ulong)*pb + (ulong)*pc + (ulong)*pd;

        if (usum != (BitConverter.IsLittleEndian ? 0x0EEEEEEECCCC6600ul : 0x226666EF115568))
        {
            Console.WriteLine("Unexpected ulong value:" + usum.ToString());
            Environment.Exit(2);
        }

        Console.WriteLine("PASSED");
        return(0);
    }
Exemplo n.º 2
0
    unsafe public static int Main() {
        UnalignedValue v = new UnalignedValue();

        v.d = 0x0FFFFFFFFFFFFFF0;
        v.c = 0x77777777;
        v.b = 0x3333;
        v.a = 0x11;

        long sum = v.a + v.b + v.c + v.d;

        if (sum != (BitConverter.IsLittleEndian ? 0x0FFFFFFFEEEE9944 : 0x11337778113388AB)) {
            Console.WriteLine("Unexpected long value:" + sum.ToString());
            Environment.Exit(1);            
        }

        SmallValue t;
        t = v.x;
        t.x += 1.0;
        v.x = t;

        byte* pa = (byte*)&v.a;
        ushort* pb = (ushort*)&v.b;
        uint* pc = (uint*)&v.c;
        ulong* pd = (ulong*)&v.d;
        
        *pd = 0x0EEEEEEEEEEEEEE0;
        *pc = 0x66666666;
        *pb = 0x2222;
        *pa = 0x00;

        ulong usum = (ulong)*pa + (ulong)*pb + (ulong)*pc + (ulong)*pd;

        if (usum != (BitConverter.IsLittleEndian ? 0x0EEEEEEECCCC6600ul : 0x226666EF115568)) {
            Console.WriteLine("Unexpected ulong value:" + usum.ToString());
            Environment.Exit(2);            
        }

        Console.WriteLine("PASSED");
        return 0;
    }