Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test-740.cs « tests « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8daaed799f46ed38ac50104f7c21840a303003ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Compiler options: -unsafe

using System;
using System.Runtime.InteropServices;

class FixedTest
{
	[StructLayout (LayoutKind.Explicit)]
	public unsafe struct Value
	{
		[FieldOffset (0)]
		public void* p;
		[FieldOffset (0)]
		public double n;
		[FieldOffset (0)]
		public long i;
		[FieldOffset (0)]
		public bool b;
	}

	[StructLayout (LayoutKind.Sequential, Pack = 4)]
	public unsafe struct TValue
	{
		public Value value;

		public TValue (long x)
		{
			value = new Value ();
			value.i = x;
		}

		public override string ToString ()
		{
			return value.i.ToString ();
		}
	}

	unsafe public static int Main ()
	{
		TValue[] values = new TValue[10];
		values[0] = new TValue (0L);
		values[1] = new TValue (1000L);
		values[2] = new TValue (1L);
		Console.WriteLine ("values: {0} {1} {2}", values[0], values[1], values[2]);
		fixed (TValue* vals = values) {
			Console.WriteLine ("fixed: {0} {1} {2}", vals[0], vals[1], vals[2]);
			if (vals[0].ToString () != "0")
				return 1;

			if (vals[1].ToString() != "1000")
				return 2;

			if (vals[2].ToString() != "1")
				return 3;
		}

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