C/C++ difference in function arguments
Munagala V. S. Ramanath
ram@netcom.com
Mon Jan 5 14:58:00 GMT 1998
Hi,
The following program:
------------------------------------------------------------------------
#include <stdio.h>
void
f( double const a[2][2] )
{
printf( "%f\n", a[0][1] ); fflush( stdout );
}
int
main( int argc, char *argv[] )
{
double a[2][2] = {{1,2},{3,4}};
f( a );
return 0;
}
------------------------------------------------------------------------
produces what seems to me to be a bogus warning when compiled
as a C program with egcs-1.0:
ram@dust tests: /d2a/exper/bin/gcc -ansi -pedantic -O2 -Wall -c bug4.c
bug4.c: In function `main':
bug4.c:13: warning: passing arg 1 of `f' from incompatible pointer type
The same program produces no warnings when compiled as a C++ program:
ram@dust tests: /d2a/exper/bin/gcc -ansi -pedantic -O2 -Wall -c bug4.C
ram@dust tests:
The files are identical:
ram@dust tests: diff bug4.[cC]
ram@dust tests:
Gcc-2.7.2 did not exhibit this dichotomy.
(Removing the 'const' in the definition of f() makes the problem go
away but I'd prefer to leave the const in.)
Ram
More information about the Gcc-bugs
mailing list