- 论坛徽章:
- 0
|
5可用积分
- [root@localhost test]# cat address.c
- #include <stdio.h>
- int main(int argc,char** argv)
- {
- int a;
- char b;
- int c;
- printf("a is 0x%08x\nb is 0x%08x\nc is 0x%08x\n",&a,&b,&c);
- return 0;
- }
- [root@localhost test]# ./address
- a is 0xbff2d700
- b is 0xbff2d6ff
- c is 0xbff2d6f8
复制代码
看出linux内存的增长方向是向Low的..这个可以见我的下一个程序
- #include <stdio.h>
- void* n;
- typedef enum
- {
- GROW_HIGH,
- GROW_LOW
- }STACK;
- STACK testStack(void* p)
- {
- n=&p;
- if(n==NULL)
- return testStack(n);
- else{
- if(n<p)
- return GROW_HIGH;
- return GROW_LOW;
- }
- }
- int main()
- {
- STACK statck_direct = testStack(NULL);
- printf("%d\n",statck_direct);
- return 0;
- }
复制代码
这个结果有点不懂
[root@localhost test]# ./address
a is 0xbff2d700
b is 0xbff2d6ff
c is 0xbff2d6f8
我个人理解的是
那么a就是0xbff2d703-0xbff2d700
b 0xbff2d700-0xbff2d6ff
c 0xbff2d6ff-0xbff2d6fb
gcc -S了下 看不懂!!! 赐教
我gcc -O2优化了下后 结果更加离谱:
[root@localhost test]# ./address
a is 0xbfa3b20c
b is 0xbfa3b213
c is 0xbfa3b208
|
|