?
? ????? PHP ??? ???? ??? ?? ??
一個(gè)對(duì)象,其標(biāo)識(shí)符在沒(méi)有存儲(chǔ)類說(shuō)明符的情況下聲明_Thread_local
,并且具有外部或內(nèi)部鏈接或存儲(chǔ)類說(shuō)明符static
,具有靜態(tài)存儲(chǔ)持續(xù)時(shí)間。它的生命周期是程序的整個(gè)執(zhí)行過(guò)程,在程序啟動(dòng)之前,它的存儲(chǔ)值只被初始化一次。
由于其存儲(chǔ)值僅初始化一次,因此具有靜態(tài)存儲(chǔ)持續(xù)時(shí)間的對(duì)象可以剖析函數(shù)的調(diào)用。
關(guān)鍵字的另一個(gè)用途static
是文件范圍。
剖析函數(shù)f()的調(diào)用。
#include <stdio.h> void f (void){ static int count = 0; /* static variable */ int i = 0; /* automatic variable */ printf("%d %d\n", i++,count++); return;} int main(void){ for (int ndx=0; ndx<10; ++ndx) f(); return 0;}
可能的輸出:
0 00 10 20 30 40 50 60 70 80 9