E
Eric Lilja
Hello! Consider this simple C program:
#include <stdio.h>
static void print_cards(const int[][13]);
int
main(void)
{
int deck[4][13] = {{0}};
print_cards(deck);
return 0;
}
static void
print_cards(const int deck[][13])
{
int row = 0;
int column = 0;
for(row = 0; row < 4; ++row)
for(column = 0; column < 13; ++column)
printf("[%i][%i] = %i\n", row, column, deck[row][column]);
}
When compiled, my compiler complains:
gcc -Wall -W -ansi -pedantic -g -c -o pass_2d_array.o pass_2d_array.c
pass_2d_array.c: In function `main':
pass_2d_array.c:28: warning: passing arg 1 of `print_cards' from
incompatible pointer type
If I remove the const from the type of the single parameter, it
compiles cleanly. Why can't it be const? It wrote a version that
operates on the 2d-array using a pointer-to-int and that can, of
course, be const.
/ Eric
#include <stdio.h>
static void print_cards(const int[][13]);
int
main(void)
{
int deck[4][13] = {{0}};
print_cards(deck);
return 0;
}
static void
print_cards(const int deck[][13])
{
int row = 0;
int column = 0;
for(row = 0; row < 4; ++row)
for(column = 0; column < 13; ++column)
printf("[%i][%i] = %i\n", row, column, deck[row][column]);
}
When compiled, my compiler complains:
gcc -Wall -W -ansi -pedantic -g -c -o pass_2d_array.o pass_2d_array.c
pass_2d_array.c: In function `main':
pass_2d_array.c:28: warning: passing arg 1 of `print_cards' from
incompatible pointer type
If I remove the const from the type of the single parameter, it
compiles cleanly. Why can't it be const? It wrote a version that
operates on the 2d-array using a pointer-to-int and that can, of
course, be const.
/ Eric