"restrict" in brackets - what is this?

John Scott jscott@posteo.net
Thu Aug 10 14:45:55 GMT 2023

This is a C99 feature. Essentially, since arrays are implicitly converted to pointers when passed to functions, this:
void foo(char s[restrict]);
is equivalent to this:
void foo(char *restrict s);

Note that the [.size] notation is neither a C feature nor a GCC extension; it's a notational convenience used in the Linux man pages. The proper way to declare a function that takes an array of a specified size is to use the static qualifier like so:
void foo(size_t array_size, char s[static array_size]);
which specifies that s must point to at least array_size elements when the function is called.

If the size argument needs to come after the array parameter, then that's what the GCC extension of being able to forward declare parameters is for:
void foo(size_t size; char [static size], size_t size);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: This is a digitally signed message part
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20230810/846e1b78/attachment.sig>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5880 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20230810/846e1b78/attachment.p7s>

More information about the Gcc-help mailing list