VS2008 函数内的局部变量为何地址不连续
#include "stdafx.h"
#include <cstdlib>
#include <iostream>
using namespace std;
void foobar()
{
int a = 10;
cout<<hex<<int(&a)<<endl;
int b = 20;
cout<<hex<<int(&b)<<endl;
}
int main(int argc, char *argv[])
{
foobar();
system("PAUSE");
return EXIT_SUCCESS;
}
output:
12fe8c
12fe80
Press any key to continue . . .
gcc下是连续的,印象中的VS也应该是连续的啊,空出来那么多的地址干啥啊,这不是浪费吗?
[解决办法]
用Release试试? 前几天好像有个帖子提到,说是VC在Debug时给变量留出空间,用来检查stack overflow的~
[解决办法]
int a = 0; int i; int arr[4]; for (i = 0; i < 6; ++i) arr[i] = 0;