This is the mail archive of the gcc-help@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]

const array warning question


Hello,

I am trying to compile the very simple program below and am getting this
error:

$ gcc -Wall -ansi -o test test.c
test.c: In function âmainâ:
test.c:17: warning: passing argument 1 of âf2â from incompatible pointer
type

$ gcc --version
gcc (GCC) 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)


Could someone tell me what trivial thing I am doing wrong? I am just
trying to make the int values of the array not modifiable in both
functions. I do not get this warning without the const modifiers.

Cheers,
Andres


test.c:

#include <stdio.h>

void f1(const int i[][2])
{
        printf("%d\n", i[0][0]);
}

void f2(const int j[][2])
{
        f1(j);
}

int main() 
{
        int m[2][2];
        m[0][0] = 5;
        f2(m);
        return 0;
}



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