本文共 1367 字,大约阅读时间需要 4 分钟。
#if 1 //内存布局的验证 #include <stdio.h> int globle_init = 0; int globle_uinit; static int globle_static = 0; int main() { int local_init = 0; static int local_static = 0; int *local_ptr; local_ptr = (int *)malloc(10); printf("address of main is %p\n", main); printf("address of globle_init is %p\n", &globle_init); printf("address of globle_uinit is %p\n", &globle_uinit); printf("address of globle_static is %p\n", &globle_static); printf("address of local_init is %p\n", &local_init); printf("address of local_static is %p\n", &local_static); printf("address of &local_ptr is %p\n", &local_ptr); printf("address of local_ptr is %p\n", local_ptr); // /* //windows address of &local_ptr is 0031FB70 stack address of local_init is 0031FB7C stack address of local_ptr is 00378820 heap address of main is 00AD1145 text address of globle_init is 00AD8130 data address of globle_static is 00AD8134 data address of local_static is 00AD8138 data address of globle_uinit is 00AD8160 data //linux address of local_init is 0x7fff4397784c stack address of &local_ptr is 0x7fff43977840 stack address of local_ptr is 0x828010 heap address of globle_uinit is 0x601064 data address of local_static is 0x601060 data address of globle_static is 0x60105c data address of globle_init is 0x601058 data address of main is 0x400650 text */ // free(local_ptr); printf("ok\n"); return 0; } #endif转载地址:http://yabji.baihongyu.com/