Names specified here
Name Description Notes Source Availability
static Multipurpose modifier L Keyword C89 C90 C95 C99 C11

The keyword static doesn't have a single clear use. The meaning depends on context.

The following skeleton of code shows four uses of static:

static int counter;

static void func(int sz, double arr[static 10])
{
  static double sum;
}

sum has block scope because it is declared inside a block statement. static gives it static storage duration, so it is created once at the start of the program's execution, and deleted when program execution ends. Without it, sum would have automatic storage duration, so a new object would be created on each entry to the function, and destroyed when the function returned.

counter has file scope, so it would already have static storage duration even without static, but the extra keyword means that counter has internal rather than external linkage. When static is applied to a function, such as func, the function has internal rather than external linkage.

The static that appears in the parameter list of func indicates that the second argument (assigned to arr) must be a pointer to the first of at least 10 elements of an array, or the behaviour would be undefined. (This feature is only available from C99.)


CHaR
Sitemap Supported
Site format updated 2024-06-05T22:37:07.391+0000
Data updated 1970-01-01T00:00:00.000+0000
Page updated 2022-06-17T21:43:05.000+0000