C
Christopher Key
Hello,
Can anyone suggest why gcc (-W -Wall) complains,
test.c:22: warning: passing arg 1 of `f' from incompatible pointer type
when compiling the following code? Change the declation of f to,
void f(int *const *const p, int *const *const q) {
prevents the warning, but I just can't see why this should be.
Many thanks,
Chris
#include <stdlib.h>
#include <stdio.h>
void f(const int *const *const p, int *const *const q);
int main() {
int **p, **q, i;
p = calloc(2, sizeof(int *));
q = calloc(2, sizeof(int *));
for (i=0; i<2; i++) {
p = calloc(2, sizeof(int));
q = calloc(2, sizeof(int));
}
p[0][0] = 41;
p[0][1] = 40;
p[1][0] = 39;
p[1][1] = 38;
f(p, q);
fprintf(stderr, "%d %d %d %d", q[0][0], q[0][1], q[1][0], q[1][1]);
for (i=0; i<2; i++) {
free(p);
free(q);
}
free(p);
free(q);
return 0;
}
void f(const int *const *const p, int *const *const q) {
q[0][0] = p[0][0] + 1;
q[0][1] = p[0][1] + 2;
q[1][0] = p[1][0] + 3;
q[1][1] = p[1][1] + 4;
}
Can anyone suggest why gcc (-W -Wall) complains,
test.c:22: warning: passing arg 1 of `f' from incompatible pointer type
when compiling the following code? Change the declation of f to,
void f(int *const *const p, int *const *const q) {
prevents the warning, but I just can't see why this should be.
Many thanks,
Chris
#include <stdlib.h>
#include <stdio.h>
void f(const int *const *const p, int *const *const q);
int main() {
int **p, **q, i;
p = calloc(2, sizeof(int *));
q = calloc(2, sizeof(int *));
for (i=0; i<2; i++) {
p = calloc(2, sizeof(int));
q = calloc(2, sizeof(int));
}
p[0][0] = 41;
p[0][1] = 40;
p[1][0] = 39;
p[1][1] = 38;
f(p, q);
fprintf(stderr, "%d %d %d %d", q[0][0], q[0][1], q[1][0], q[1][1]);
for (i=0; i<2; i++) {
free(p);
free(q);
}
free(p);
free(q);
return 0;
}
void f(const int *const *const p, int *const *const q) {
q[0][0] = p[0][0] + 1;
q[0][1] = p[0][1] + 2;
q[1][0] = p[1][0] + 3;
q[1][1] = p[1][1] + 4;
}