首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

VS2008 函数内的局部变量为何地址不连续解决方案

2012-05-06 
VS2008 函数内的局部变量为何地址不连续#include stdafx.h#include cstdlib#include iostreamusing

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; 

热点排行