blob: 7f97577ff908e26c8a03f024dc46f9c3e44fd7ef (
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
|
// Compiler options: -unsafe
using System;
using System.Runtime.InteropServices;
class A
{
[StructLayout (LayoutKind.Sequential)]
struct S { int x; }
public class B
{
[StructLayout (LayoutKind.Sequential)]
struct S { int x; int y; }
S s;
public B () {
string error = "";
unsafe {
if (typeof (S *).GetElementType () != typeof (A.B.S))
error += " composed cast (pointer),";
if (sizeof (S) != sizeof (A.B.S))
error += " sizeof,";
S *p1 = stackalloc S [1];
if ((*p1).GetType () != typeof (A.B.S))
error += " local declaration, 'stackalloc' keyword,";
fixed (S *p2 = &s) {
if ((*p2).GetType () != typeof (A.B.S))
error += " class declaration, 'fixed' statement,";
}
}
if (error.Length != 0)
throw new Exception ("The following couldn't resolve S as A+B+S:" + error);
}
}
public static void Main()
{
object o = new A.B();
}
}
|