This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Strange gcc specific warning
- From: Tolga Dalman <ates100 at web dot de>
- To: Frank Klemm <pfk at fuchs dot offl dot uni-jena dot de>
- Cc: gcc at gcc dot gnu dot org
- Date: Sun, 26 Jan 2003 22:26:47 +0000
- Subject: Re: Strange gcc specific warning
- References: <20030124053027.A2577@fuchs.offl.uni-jena.de>
hi,
On Fri, 24 Jan 2003 05:30:27 +0100 Frank Klemm <pfk@fuchs.offl.uni-jena.de> wrote:
> Hi,
>
> gcc is the only compiler which complains about passing R/W arrays to a read
> only function. Can this been removed?
> Otherwise most people will remove this warning by removing the const from
> the print() function.
>
> =====================================================================
> /*
> * gcc: strange warning, why ???
> * g++: okay
> * all other compilers: okay, no warning
> */
>
> #include <stdio.h>
>
>
> void
> print ( /* IN */ const float A [2] [16] )
> {
> int i;
> int j;
>
> for ( i = 0; i < 2; i++ ) {
> for ( j = 0; j < 16; j++ )
> printf ("%12.6f", A [i] [j] );
> printf ( "\n" );
> }
> }
>
>
> void
> invert ( /* IN OUT */ float A [2] [16] )
> {
> int i;
> int j;
>
> for ( i = 0; i < 2; i++ )
> for ( j = 0; j < 16; j++ )
> A [i] [j] = -A [i] [j];
> }
>
>
> int
> main ( void )
> {
> float Array [2] [16];
>
> invert ( Array );
> print ( Array );
>
> return 0;
> }
>
> =====================================================================
>
you can turn off all warnings with the "-w" option. since this is not always
desirable, there must be a more specific option for this (which i don't know).
anyway, in general, you'd do some cast, but in your case it won't work.
this is what i mean:
main ( void )
{
float Array [2] [16];
invert ( Array );
print ( (*((const float[][]*) &Array) );
return 0;
}
in your case, this "trick" won't work, because you're not allowed to cast to
an array type.
i'd suggest, you either remove the const in your print function, or use a
float** instead float[2][16] as function argument.
please consider that passing a non-const value to a const function is
definitively a type-mismatch, so a warning message is apropriate and sensible.
brg,
Tolga Dalman.