Some versions of documentation declare certain functions like parameters declared in the signature and, e.g., Arch Linux:
ssize_t read(size_t count;
int fd, void buf[count], size_t count);
GCC just ignores the forward declaration, but it stumbles over an obviously illegal array of void
.
Is that some universally accepted mnemonic (another version I saw was buf[.count]
) and GCC ignores it or is it an extension?
The forward declaration of a parameter is a GCC extension, so GCC accepts it.
The declaration of an array of void
is an error or deliberate misuse of C in the documentation. A declaration of a parameter as an array is automatically adjusted to be a pointer, so the documentation author likely thought void buf[count]
would express a declaration of buf
to have type void *
, along with a suggestion that it points to the first of at least count
elements (of some type known to the caller). However, the C standard has a constraint (in C 2024 6.7.7.3) that the element type of an array in a declaration must be complete (its size must be known to the compiler at that moment), and void
is not a compete type. So a compiler will detect and report this constraint violation before the adjustment would be made.
A correct declaration for Unix systems, from The Open Group Base Specifications, would be:
ssize_t read(int fildes, void *buf, size_t nbyte);