[Mono-dev] StructLayout with misaligned offsets

tcmichals tcmichals at msn.com
Wed Apr 12 10:22:41 EDT 2006


namespace testCode
{
    class Program
    {
        [StructLayout(LayoutKind.Sequential, Pack = 1 /*, CharSet = 
CharSet.Ansi */)/*, Serializable*/]
        public struct tagSDK
        {

            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
            public ushort[] inter;
            public ushort integ;
            public ushort mode;
            public ushort imaging;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
            public ushort[] Avg;
            public ushort numOfIntervals;
            public tagSDK(int val)
            {
                this.inter = new ushort[12];
                this.inter[0] = 0;
                this.Avg = new ushort[12];
               Avg[0] = 0;
                integ = 0;
                imaging = 0;
                imaging2 = 0;
                numOfIntervals = 0;
                mode = 0;
           }
        };
        static void Main(string[] args)
        {
            tagSDK t= new tagSDK(0);
            Console.WriteLine("Hello World");
        }
    }
}

When I attempt to execute the following program the following message is 
generated
* ERROR **: file object.c: line 509 (compute_class_bitmap): assertion 
failed: ((field->offset % sizeof(gpointer)) == 0)

If I change The alignment of Avg to be on a 4 byte boundry it works, 
sugguestions?









More information about the Mono-devel-list mailing list