记得堆栈空间是从高地址向低地址伸展的,可为何我在.Net下编译后的程序地址确是由低向高增长的呢?
测试代码如下:
public static class Test
{
public unsafe static void Main()
{
int x, y;
x = 10;
y = 50;
int*
pX, pY,pZ;
pX = &(x);
pY = &(y);
pZ = pX
- 1; //pZ想指向y
Console.WriteLine("Address of x: {0:X}",(uint)pX);
Console.WriteLine("Address of y: {0:X}",(uint)pY);
Console.WriteLine(*pZ);
Console.ReadKey();
}
}
调试时的输出:(可以证明堆栈由高地址向低地址伸展)
Address of x: 3C4ECC4
Address of y: 3C4ECC0
50
可运行时的输出却变成了:(由低地址向高地址伸展了?!)
Address of x: 12F45C
Address
of y: 12F460
14090491 <-变成了无效值了-_-!
请问是什么原因?