This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/33076] Warning when passing a pointer to a const array to a function that expects a pointer to a non-cast one
- From: "raeburn at raeburn dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 15 Aug 2007 06:15:20 -0000
- Subject: [Bug c/33076] Warning when passing a pointer to a const array to a function that expects a pointer to a non-cast one
- References: <bug-33076-14983@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #2 from raeburn at raeburn dot org 2007-08-15 06:15 -------
Subject: Re: New: Warning when passing a pointer to a const array to a
function that expects a pointer to a non-cast one
On Aug 14, 2007, at 23:45, martin dot ferrari at gmail dot com wrote:
> Sorry if I'm misunderstanding something or this is a FAQ, but I
> couldn't find
> any reference, except for a unanswered mail with the same problem
> from 2000 at
> http://gcc.gnu.org/ml/gcc-bugs/2000-10/msg00337.html (and I don't
> find it in
> bugzilla either). The code looks semantically correct to me, the
> function
> declares that it won't touch the data and I'm passing a non-const
> data. If the
> typecast is not to an array, the warning goes away.
> /home/martin/test.c:8: warning: passing argument 1 of ?foo? from
> incompatible
> pointer type
> typedef int caca[3];
> void foo (const caca* p);
> void bar(caca *c) {
> foo(c);
> }
I think this might be related to the bug report I filed in 31887 --
and I'm starting to think that we might both be wrong.
Weird as it seems, my reading of the C spec, section 6.7.3 says that
the qualifier (const, in both our cases, but it would apply to
volatile as well) applies only to the array element type, and does
*not* apply to the array type itself. So this isn't like assigning a
"char *" value to a "const char *"; you're dealing with pointers to
two different array types (which happen to have similar but
differently-qualified element types).
I'm not 100% sure I believe this interpretation, because it seems to
needlessly prohibit perfectly reasonable code, and when I asked on
comp.std.c a couple weeks back, I got some mixed feedback. But at
the moment, that's my reading of the spec....
Ken
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33076