void fun(void){
int a;
int b = 0;
int c = 1;
staticint x;
staticint y = 0;
staticint z = 1;
return ;
}
//a b c 在栈中 //注意,在这段代码被执行的时候会去读代码段,然后开始在栈中 定义变量,a b c.这段代码执行完毕,栈被销毁.下次 还是按照读代码段,在栈中定义a b c 的方式做//x y 在.bss段中(数据段的一种)//z在.data段中(数据段的一种)//a b c x y z 只能被fun函数使用//存储在数据段的变量的存活期处于整个进程运行的时候.所以不能被重复初始化.//fun在代码段中
修饰全局变量
int a;
int b = 0;
int c = 1;
staticint x;
staticint y = 0;
staticint z = 1;
//a b x y 在.bss段//c z 在.data段//a b c 可以被其他文件引用,引用前需要被声明//x y z 不可以被其他文件引用
nm elf-file
例如
$ nm main
08049f28 d _DYNAMIC
08049ff4 d _GLOBAL_OFFSET_TABLE_
0804851c R _IO_stdin_used
w _Jv_RegisterClasses
08049f18 d __CTOR_END__
08049f14 d __CTOR_LIST__
08049f20 D __DTOR_END__
08049f1c d __DTOR_LIST__
08048618 r __FRAME_END__
08049f24 d __JCR_END__
08049f24 d __JCR_LIST__
0804a018 A __bss_start
0804a010 D __data_start
080484d0 t __do_global_ctors_aux
08048390 t __do_global_dtors_aux
0804a014 D __dso_handle
w __gmon_start__
080484c2 T __i686.get_pc_thunk.bx
08049f14 d __init_array_end
08049f14 d __init_array_start
080484c0 T __libc_csu_fini
08048450 T __libc_csu_init
U __libc_start_main@@GLIBC_2.00804a018 A _edata
0804a020 A _end
080484fc T _fini
08048518 R _fp_hw
080482d4 T _init
08048360 T _start
0804a018 b completed.61590804a010 W data_start
0804a01c b dtor_idx.6161080483f0 t frame_dummy
U getchar@@GLIBC_2.008048414 T main
U printf@@GLIBC_2.0
作用修饰局部变量void fun(void){ int a; int b = 0; int c = 1; static int x; static int y = 0; static int z = 1; return ;}//a b c 在栈中 //注意,在这段代码被执行的时候会去读代码段,然后开始在栈中 定义变量,a b c.这段代码