#include <stdio.h>
int a; //.bss GLOBAL
int b=0; //.bss GLOBAL
int c=2; //.data GLOBAL
const int d; //.bss GLOBAL
const int e=0; //.rodata GLOBAL
const int f=2; //.rodata GLOBAL
static int h; //.bss LOCAL
static int i=0; //.bss LOCAL
static int j=2; //.data LOCAL
static const int k; //.bss LOCAL
static const int l=0;//.rodata LOCAL
static const int m=2;//.rodata LOCAL
int main(void)
{
int a_1;
int b_1=0;
int c_1=2;
const int d_1;
const int e_1=0;
const int f_1=2;
static int h_1; //.bss LOCAL
static int i_1=0; //.bss LOCAL
static int j_1=2; //.data LOCAL
static const int k_1; //.bss LOCAL
static const int l_1=0;//.rodata LOCAL
static const int m_1=2;//.rodata LOCAL
return 0;
}
1.全局變量被static修飾之後,作用域變為LOCAL,生存週期不變
局部變量被static修飾之後,作用域沒變,生存週期延長(變為符號)
2.全局變量被const修飾之後,對於未初始化的放到.bss段、已初始化的存放到.rodata段
局部變量被const修飾之後,作用域與生存週期都不變,只是限定簡單的設定,其值可變(通過指針或(void *)強轉)
3.未標出的變量存放在棧幀上,其作用域與生存週期僅限當前模塊