This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

warning about const multidimensional array as function parameter



Hi all,

although this is a problem of the C standard, I still
find it annoying that the following code produces warnings
about incompatible pointer types (this has been discussed 
before, see below):

extern void test(const double x[2][2]);

void foo(void)
{
	double x[2][2];
	const double (*y)[2] = x;
	test(x);
}

Could we have an option to turn these warnings off?
Or, even better, have these warnings only with '-pedantic'?

I could try to come up with a patch...


This is not allowed because in C the qualifier always 
belongs to the element type, and the allowed pointer
conversion rules do not include this case - which I assume
is an oversight of the standards committee. 

Converting a pointer to an array to a pointer to a
constant array (i.e. an array with constant element type)
seems to be a perfectly reasonable and safe thing to do. 
This is different from the case of converting a pointer 
to a pointer, e.g. char** to const char** which is unsafe.


Martin


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47143
http://stackoverflow.com/questions/4573349/c-function-const-multidimensional-array-argument-strange-warning
http://gustedt.wordpress.com/2011/02/12/const-and-arrays/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]