Re: "restrict" in brackets - what is this?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 8/10/23 09:45, John Scott via Gcc-help wrote:
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);

Thank you.  I wasn't familiar with the "array" version of the syntax.

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.

I can't believe that I didn't know about this before now.

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);

Cool!

Thanks again!

--
========================================================================
Google                                      Where SkyNet meets Idiocracy
========================================================================





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux