Strange const warning

Jonathan Kinsey jon_kinsey@hotmail.com
Thu Dec 28 21:55:00 GMT 2006


Ian Lance Taylor wrote:
> 
> 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.

Thanks for the replies, you are right the function is being treated
something like:
	void test(int (*a)[1])

What's slightly strange is that if I make the array in main() const it
compiles without the warning.

Obviously removing the const in the test() argument is ok, it's a pity
you can't mark a multi-dimensional array parameter as const, it's just
part of the leagacy of C's pointer/array loose definition.

Jon



More information about the Gcc-help mailing list