uint16_t integer_read_16(const uint8_t buf[static 2]);
I've never seen the keyword static used in this way before. I can't
seem to find any reference to it online. GCC does accept it as legal.
Has this syntax always existed? If not, when was it added to the C
standard? What does it mean?
Thanks,
Shaun
--
comp.lang.c.moderated - moderation address: cl...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
> I saw the following declaration in the source code of xzutils:
>
> uint16_t integer_read_16(const uint8_t buf[static 2]);
>
> I've never seen the keyword static used in this way before. I can't
> seem to find any reference to it online. GCC does accept it as legal.
> Has this syntax always existed? If not, when was it added to the C
> standard? What does it mean?
It appeared in C99, and specifies the minimal number of data the array
contains. You can put "const" there also.
Like you I couldn't find much on this feature. Here is a short
explanation:
http://publib.boulder.ibm.com/infocenter/zos/v1r9/index.jsp?topic=/com.ibm.zos.r9.cbclx01/static_array_index.htm
HTH,
-- Alain.
Thanks for the link. That clears up my question. I found this usage
interesting:
void foo(int arr [static const i]); /* arr points to at least i ints;
i is computed at run
time. */
I tried the following use case:
int read(int fd, const char buf[static count], unsigned count)
{
return count;
}
but GCC didn't like it.
foo.c:1: error: 'count' undeclared here (not in a function)
However, the following declaration was acceptable:
int read(int fd, unsigned count, const char buf[static count])
{
return count;
}
They're going to have to redefine the order of arguments of read. ;)
Cheers,
Shaun