Is passing NULL valid when array parameter uses [static 0] in C99?
13:46 17 Apr 2026
Consider the following code:
void foo(size_t len, int array[static len])
{
}
int main(int argc, char *argv[])
{
foo(0, NULL);
return 0;
}
The function foo declares its second parameter using the C99 [static len] syntax, which guarantees to the compiler that the passed pointer points to at least len elements.
My question is: is the call foo(0, NULL)strictly conforming to the C99 standard?
My analysis so far:
The relevant passage is §6.7.5.3 p7 of the C99 standard:
A declaration of a parameter as ‘‘array of type’’ shall be adjusted to ‘‘qualified pointer to type’’, where the type qualifiers (if any) are those specified within the [ and ] of the array type derivation. If the keyword static also appears within the [ and ] of the array type derivation, then for each call to the function, the value of the corresponding actual argument shall provide access to the first element of an array with at least as many elements as specified by the size expression.
Notice that the standard does not explicitly say "the argument must be non-null". The non-null requirement is only implicit: a NULL pointer cannot "provide access to the first element" of anything, by definition. There is no sentence in C99 that directly states a non-null requirement.
This distinction matters for the case len == 0: when the size expression evaluates to zero, the standard requires the argument to provide access to the first element of an array of at least 0 elements. This is a vacuously satisfied constraint, there is no element to access, so NULL does not violate the "provide access" requirement.
Compiler stderr
:9:5: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
9 | foo(0, NULL);
| ^ ~~~~
:3:26: note: callee declares array parameter as static here
3 | void foo(size_t len, int array[static len])
| ^ ~~~~~~~~~~~~
1 warning generated.
Program returned: 0
Specific questions:
Does the C99 standard define any behavior for [static 0], or is a zero-length static array parameter itself already undefined/unspecified?
If the static N constraint is vacuously satisfied when N == 0, does that make foo(0, NULL) fully defined behavior?
Does passing a VLA-based bound (i.e., [static len] where len is a runtime variable equal to 0) change the analysis compared to a compile-time constant [static 0]?
We use cookies to ensure the best experience on our website. This includes analytics, personalization, and marketing purposes. Some cookies are essential for the website to function properly.
By clicking "Accept", you consent to our use of cookies. You can read more about how we use cookies and how you can change your preferences in our Privacy Policy.