two dimensional array of const chars Warning
Erick Branderhorst
Erick.Branderhorst@asml.nl
Mon Sep 28 23:59:00 GMT 1998
Hi,
Have been trying to compile a piece of code containing a two dimensional
array of constant char arrays (i.e. a three dimensional array of const
chars). The most recent snapshot of the egcs compiler (and all older
versions of gcc) warn about a incompatible pointer type. Removing the
`const' will not show a warning, however the `const' makes more visible
what kind of array this is, and that the function will not change it.
Below a piece of code which will show the warning.
Erick & Henk
#include <stdio.h>
#define l_row 2
#define l_col 3
#define l_str_size 4
static void p_str_table_print( const char str_table[l_row][l_col][l_str_size] )
/* ***** */
{
int row ;
int col ;
for ( row = 0; row < l_row; row++ )
{
for ( col = 0; col < l_col; col++ )
{
printf( "%3s", str_table[row][col] ) ;
}
printf( "\n" ) ;
}
}
int main( void )
{
char str_table[l_row][l_col][l_str_size] =
{
{"1a","1b","1c" },
{"2a","2b","2c" }
} ;
printf( "print table...\n" ) ;
p_str_table_print( str_table ) ;
printf( "done.\n" ) ;
return 0 ;
}
More information about the Gcc-bugs
mailing list