作者shps90060505 (蓝岚)
看板EE_DSnP
标题[请益] stack memory alignment的问题
时间Wed Oct 10 00:25:06 2012
对於memory alignment的问题,
老师曾在课堂上给过例子,
在Stack中的记忆体位置是往下排,
但我写的code却往上排@@ 不知发生了什麽事?
还请大家帮忙解答
code和执行结果如下:
---------------------------code-------------------------------
#include<iostream>
using namespace std;
void print(int a, int b){
int c;
int d;
cout<< "address of a and b: "<< &a << " " << &b << endl;
cout<< "address of c and d: "<< &c << " " << &d << endl;
}
int main()
{
int e;
int f;
print(10,20);
cout<< "address of e and f: "<< &e << " " << &f << endl;
return 0;
}
--------------------------------------------------------------
----------------------------result----------------------------
address of a and b: 0x7fff2497afd
c 0x7fff2497afd
8
address of c and d: 0x7fff2497afe
8 0x7fff2497afe
c
address of e and f: 0x7fff2497b00
8 0x7fff2497b00
c
---------------------------------------------------------------
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.218.188
1F:→ shps90060505:自己回自己...因为他们都是int所以往上排 10/10 00:30
2F:→ shps90060505:如果是int c; double d;那就会变往下排 10/10 00:30
3F:→ shps90060505:不过function的参数我目前还没办法解释 只提供现象.. 10/10 00:31
4F:推 timrau:function parameters在标准里并没有规定它们怎麽排 10/10 01:30