目录搜索
文字
分享

一个对象,其标识符在没有存储类说明符的情况下声明_Thread_local,并且具有外部或内部链接或存储类说明符static,具有静态存储持续时间。它的生命周期是程序的整个执行过程,在程序启动之前,它的存储值只被初始化一次。

注意

由于其存储值仅初始化一次,因此具有静态存储持续时间的对象可以剖析函数的调用。

关键字的另一个用途static是文件范围。

剖析函数f()的调用。

#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