liveBook · Manning

Static array parameter qualifier

As explained in Modern C

A static array parameter is a C array-parameter declaration whose static bound promises that the argument points to at least one element.

A non-null single-object parameter

void func(double a[static 1]); Here, array syntax documents that a must point to at least one double. The static 1 notation distinguishes this contract from a parameter that may receive a null pointer. section 15.0

TAKEAWAY: A static array parameter uses array-parameter syntax to state a minimum number of pointed-to elements. The bound may describe one object or a known collection. section 15.0

Choose the declaration according to the pointer contract:

  • Use static 1 for a pointer to one object that must be non-null: void func(double a[static 1]); section 15.0
  • Use static N for a pointer to at least N elements: void func(double a[static 7]); section 15.0
  • Use a VLA parameter when the element count is supplied separately: void func(size_t n, double a[n]); section 15.0
  • Use pointer syntax when null is permitted: void func(double *a); section 15.0
void func(double a[static 1]);
!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":4}],[{\"line\":0,\"ch\":10},{\"line\":0,\"ch\":16}],[{\"line\":0,\"ch\":19},{\"line\":0,\"ch\":25}]]"}
!@%STYLE%@!

Inspect the complete static 1 declaration and its highlighted syntax. section 15.0

How Modern C covers it

How deep it goes
Defines static 1 and static N notation, then contrasts them with VLA and nullable pointer declarations.
Examples
Uses func declarations with static 1, static 7, a VLA bound, and a plain pointer.
What you can do after
Apply the notation to declare C functions with explicit non-null or minimum-array-size expectations.
How it connects
Connects array parameters with pointers, variable-length arrays, null pointers, and dynamic allocation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.