[Mono-osx] fixed in unsafe structs

oleg z ru.zelyony at gmail.com
Sun May 1 06:20:33 EDT 2011


//***************************************************************************
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
    public unsafe struct SomeType
    {
        public int i1, i2, i3;

        //public fixed int vec[10];
        public fixed long vec[10]; // got a SIGABRT
    }

    class Program
    {

        static unsafe void Main( string[] args )
        {
            var c = new SomeType();
            var c2 = new SomeType();
            Console.WriteLine( "sizeof={0}", Marshal.SizeOf( c));
            c.i1 = c2.i1 = 10;
            c.i2 = c2.i2 = 8;
            c.i3 = c2.i3 = 1;
            c.vec[0] = c.vec[5] = c.vec[9] = c2.vec[0] = c2.vec[5] =
c2.vec[9] = 123;
            Console.WriteLine( "{0} {1} {2} {3} {4} {5} {6} {7}", c.i1,
c.i2, c.i3, c.vec[0], c.vec[5], c.vec[9], c.vec[3], c.vec[7] );
            Console.WriteLine( "{0} {1} {2} {3} {4} {5} {6} {7}", c2.i1,
c2.i2, c2.i3, c2.vec[0], c2.vec[5], c2.vec[9], c2.vec[3], c2.vec[7] );

            Console.ReadLine();
        }
    }
}
//***************************************************************************
compile with unsafe context ON console app

this code is work incorrectly in MonoFramework 2.10.1.3 sizeof(c) == 24
(valid 52), and memory(c2) is rewritten from c
in MonoFramework 2.10.2.5.4 (MDK) code with INT work correctly
BUT I've got SIGABRT in runtime for LONG arrays (uncomment line in struct
definition)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-osx/attachments/20110501/7164cff7/attachment-0001.html 


More information about the Mono-osx mailing list