gcc and pointer-to-arrays

M

mjkrol

Crossposting from comp.lang.c.moderated.


On gcc 4.2.4 with `-O3' I am getting a warning for the following code.

void foo(const float rgba[][4])
{
}

void bar(float rgba[][4])
{
foo((const float (*)[4]) rgba);
}

int main (void)
{
float color[3][4];
foo(color);
return 0;
}


$ gcc -O3 foobar.c
foobar.c:7: warning: passing argument 1 of "foo" from incompatible
pointer type


Why turning optimisations on would generate this kind of warning? Is
this a bug in gcc?

Thanks.
 
B

Ben Bacarisse

mjkrol said:
Crossposting from comp.lang.c.moderated.

Are you? I think you are multiposting not crossposting.
On gcc 4.2.4 with `-O3' I am getting a warning for the following code.

void foo(const float rgba[][4])
{
}

void bar(float rgba[][4])
{
foo((const float (*)[4]) rgba);
Fine.

}

int main (void)
{
float color[3][4];
foo(color);

Constraint violation.
return 0;
}


$ gcc -O3 foobar.c
foobar.c:7: warning: passing argument 1 of "foo" from incompatible
pointer type


Why turning optimisations on would generate this kind of warning? Is
this a bug in gcc?

The code contains a constraint violation so a diagnostic is required
if gcc is being invoked in some standard-conforming mode.

By default, gcc does not quite process C, so it is not really bound by
the standard. I'd hope for a diagnostic at all -O levels, but unless
you are asking for standard C, it is permitted to do pretty much what
it likes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,125
Latest member
VinayKumar Nevatia_
Top