C#
真的很大struct
,没有递归,纯C#,不是不安全的代码。
public struct Wyern
{
double a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
}
public struct Godzilla
{
Wyern a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
}
public struct Cyclops
{
Godzilla a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
}
public struct Titan
{
Cyclops a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
}
class Program
{
static void Main(string[] args)
{
// An unhandled exception of type 'System.StackOverflowException' occurred in ConsoleApplication1.exe
var A=new Titan();
// 26×26×26×26×8 = 3655808 bytes
Console.WriteLine("Size={0}", Marshal.SizeOf(A));
}
}
作为踢手,它使调试窗口崩溃,指出 {Cannot evaluate expression because the current thread is in a stack overflow state.}
和通用版本(感谢NPSF3000的建议)
public struct Wyern<T>
where T: struct
{
T a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
}
class Program
{
static void Main(string[] args)
{
// An unhandled exception of type 'System.StackOverflowException' occurred in ConsoleApplication1.exe
var A=new Wyern<Wyern<Wyern<Wyern<int>>>>();
}
}