Warning when using const pointer to fixed size array

me22 me22.ca@gmail.com
Tue Dec 1 16:29:00 GMT 2009


2009/12/1 Sergei Organov <osv@javad.com>:
> me22 <me22.ca@gmail.com> writes:
>> 2009/12/1 Sergei Organov <osv@javad.com>:
>>>
>>> void boo(const int p[9]);
>>>
>>> You see? Use the second, simpler declaration, and you are OK.
>>>
>>
>> But then p is a pointer, not an array.
>
> But then in
>
> void foo(const int (* p)[9]);
>
> 'p' is also a pointer, not an array.
>

Sorry; You're of course right.

I should been less specific and more useful and said, "But then you
lose the size of the array".

I've seen such things used in C++ like this:

    template <typename T, size_t N>
    size_t array_length(T (&)[N]) { return N; }

In place of sizeof(p)/sizeof(*p), in order to get a compilation
failure if a pointer is accidentally passed.



More information about the Gcc-help mailing list