Re: Warning when using const pointer to fixed size array

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

 



2009/12/1 Sergei Organov <osv@xxxxxxxxx>:
> me22 <me22.ca@xxxxxxxxx> writes:
>> 2009/12/1 Sergei Organov <osv@xxxxxxxxx>:
>>>
>>> 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.

[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