https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121331
Bug ID: 121331
Summary: New dialect flag: -farray-parameters-are-arrays
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: [email protected]
Target Milestone: ---
This is a stronger version of -farray-parameters-are-const, proposed in
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121271>.
It would make array parameters work as real arrays in every way: sizeof(),
typeof(), _Generic(), ...
This would affect the function scope, but not it's callers.
Let's write some examples, to make it clear:
void
f(int size, char buf[size], pid_t pid)
{
if (stprintf(buf, _Countof(buf), "/proc/%d/", pid) == -1)
return;
...
return;
}
char *a = malloc(100);
f(100, a, 0); // Ok; at call site pointers are valid.
void
g(int size, char buf[size], pid_t pid)
{
buf = NULL; // error: assignment to expression with array type
}
void
h(char *buf;
int size, char buf[size], pid_t pid); // error: redeclaration with
different type
void
i(char buf[];
int size, char buf[size], pid_t pid); // okay
void
i(char buf[size];
int size, char buf[size], pid_t pid); // okay