读书人

VS2008 函数内的局部变量为何地址不连

发布时间: 2012-05-06 16:15:43 作者: rapoo

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的~
[解决办法]

探讨
引用:
用Release试试? 前几天好像有个帖子提到,说是VC在Debug时给变量留出空间,用来检查stack overflow的~




哦? 能否详细说说看?

[解决办法]
C/C++ code
    int a = 0;    int i;    int arr[4];    for (i = 0; i < 6; ++i)         arr[i] = 0; 

读书人网 >C++

热点推荐