Warning when using const pointer to fixed size array
Sergei Organov
osv@javad.com
Tue Dec 1 15:08:00 GMT 2009
Aaron Rocha <hxdg21@yahoo.com> writes:
[...]
> This is ok if you are working with buffers that may vary in size. But if
> your buffers have a fixed size, wouldn't it be better to do this?
>
> void foo(const int (* p)[9]);
$ cat array.c
void foo(const int (* p)[9]);
void boo(const int p[9]);
int main()
{
int array[9];
foo(&array);
boo(array);
return 0;
}
$ gcc -c -W -Wall array.c
array.c: In function âmainâ:
array.c:6: warning: passing argument 1 of âfooâ from incompatible pointer type
$
You see? Use the second, simpler declaration, and you are OK.
-- Sergei.
More information about the Gcc-help
mailing list