This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Strange const warning
- From: Ian Lance Taylor <iant at google dot com>
- To: Jonathan Kinsey <jon_kinsey at hotmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: 28 Dec 2006 09:26:04 -0800
- Subject: Re: Strange const warning
- References: <BAY108-DAV17C8A42A4D9B30A543F470F8C70@phx.gbl>
Jonathan Kinsey <jon_kinsey@hotmail.com> writes:
> The test.c file below gives a warning "passing arg 1 of `test' from
> incompatible pointer type", why is this? I'm using gcc 3.4.2.
>
> #include "stdio.h"
>
> void test(const int a[1][1])
> {
> printf("%d\n", a[0][0]);
> }
>
> int main()
> {
> int a[1][1] = {{0}};
> test(a);
> return 0;
> }
This is a generic C question, not a question specific to gcc.
The reason is that when arrays are passed as parameters, they decay to
pointers. The effect is that the const qualifer does not work as you
expect it to. If you remove the const, you will not get the warning.
For details on why it works this way, look for a C FAQ or a C
standards mailing list.
Ian