This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Warning when using const pointer to fixed size array
- From: "John (Eljay) Love-Jensen" <eljay at adobe dot com>
- To: Aaron Rocha <hxdg21 at yahoo dot com>
- Cc: GCC-help <gcc-help at gcc dot gnu dot org>
- Date: Tue, 1 Dec 2009 07:57:10 -0800
- Subject: Re: Warning when using const pointer to fixed size array
Hi Aaron,
> void foo(const int (* p)[9]);
>
> In this case, you are guaranteed that the caller is giving you a valid
> buffer. Otherwise, you will get a compile error message which will help
> you quickly detect a problem.
I think...
In C, arrays degenerate into pointers at the drop of a hat.
These two kinds of pointers are compatible:
int* p;
int const* p;
The two kinds of pointers are compatible:
int** p;
int* const* p;
The two kinds of pointers are not compatible:
int** p;
int const** p;
Your situation is like the third case. The const is not
two-levels-of-indirection compatible.
Anyone have ISO 9899 on hand to cite chapter & verse?
HTH,
--Eljay