T
Tim Woodall
How do I get gcc to like the following code (other than the obvious
cast)?
struct DATA {
char arr[12][12];
};
void test_func(const char (*data)[12]);
const struct DATA cdata = {{{0}}};
struct DATA data;
void testme(void)
{
test_func(cdata.arr);
test_func(data.arr); /* Line 13 */
}
$ gcc -W -Wall -ansi -pedantic -c arr.c
arr.c: In function 'testme':
arr.c:13: warning: passing argument 1 of 'test_func' from incompatible
pointer type
$ g++ -W -Wall -ansi -pedantic -c arr.c
$
It appears to be OK in C++ but not in C. I'm guessing that I'm missing a
const somewhere but I cannot work out where.
I've even tried a typedef const char ARR[12]; and then const ARR* data
parameter but that hasn't worked either. I get exactly the same warning
when I try to pass the non-const version.
(gcc 4.3.2 in case it's a bug in gcc that has been fixed in a later
version)
Tim.
cast)?
struct DATA {
char arr[12][12];
};
void test_func(const char (*data)[12]);
const struct DATA cdata = {{{0}}};
struct DATA data;
void testme(void)
{
test_func(cdata.arr);
test_func(data.arr); /* Line 13 */
}
$ gcc -W -Wall -ansi -pedantic -c arr.c
arr.c: In function 'testme':
arr.c:13: warning: passing argument 1 of 'test_func' from incompatible
pointer type
$ g++ -W -Wall -ansi -pedantic -c arr.c
$
It appears to be OK in C++ but not in C. I'm guessing that I'm missing a
const somewhere but I cannot work out where.
I've even tried a typedef const char ARR[12]; and then const ARR* data
parameter but that hasn't worked either. I get exactly the same warning
when I try to pass the non-const version.
(gcc 4.3.2 in case it's a bug in gcc that has been fixed in a later
version)
Tim.