[Bug c/33076] Warning when passing a pointer to a const array to a function that expects a pointer to a non-cast one

2007-11-20 Thread m-matti-a dot lehtonen at iki dot fi


--- Comment #10 from m-matti-a dot lehtonen at iki dot fi  2007-11-20 21:53 
---
This code piece cannot compiled without warnings or errors.

/*! Presentation of transformation matrix */
typedef coordinate_ttransform_matrix_t[ 4 ][ 4 ];
...
void
  transform_concat
  (
transform_matrix_ttransform,
transform_matrix_t const  transform1,
transform_matrix_t const  transform2
  );
...
void
  transform_rotate
  (
transform_matrix_ttransform,
real_t const  angles[ 3 ]
  )
{
  transform_matrix_t
temp;

...
  transform_concat( transform, transform, temp );
...
}
Without casts I got two warnings:
warning: passing argument 2 of #8216;transform_concat#8217; from incompatible
pointer type
warning: passing argument 3 of #8216;transform_concat#8217; from incompatible
pointer type

And if arument 2 and 3 are casted as
  transform_concat( transform, (const transform_matrix_t) transform, (const
transform_matrix_t) temp );

Then I got two errors:
error: cast specifies array type
error: cast specifies array type


-- 

m-matti-a dot lehtonen at iki dot fi changed:

   What|Removed |Added

 CC||m-matti-a dot lehtonen at
   ||iki dot fi


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33076



[Bug c/33076] Warning when passing a pointer to a const array to a function that expects a pointer to a non-cast one

2007-09-26 Thread jozef dot behran at krs dot sk


--- Comment #6 from jozef dot behran at krs dot sk  2007-09-26 12:06 ---
 Neither C nor C++ have qualified array types, only arrays of qualified 
 element types, but C++ has different rules from C regarding conversions 
 involving qualifiers, which allow some conversions (involving arrays or 
 pointers to pointers) not allowed in C.

Could you give me reference in the C standard where this is stated ? The
section 6.7.3, paragraph 8, says nothing about C/C++ not having qualified array
types, it only says that a qualifier applied to an array type holds for the
element type of the array type (these two are not the same things, see bug
16602 for more discussion about the topic).


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33076



[Bug c/33076] Warning when passing a pointer to a const array to a function that expects a pointer to a non-cast one

2007-09-26 Thread jozef dot behran at krs dot sk


--- Comment #7 from jozef dot behran at krs dot sk  2007-09-26 12:18 ---
 Neither C nor C++ have qualified array types, only arrays of qualified 
 element types, but C++ has different rules from C regarding conversions 
 involving qualifiers, which allow some conversions (involving arrays or 
 pointers to pointers) not allowed in C.

And another point: Whether C/C++ have or don't have qualified array types,
still the difference between the const caca * and caca * types is a const
qualifier being applied to some part of the caca * base type. Therefore the
types must be compatible when the automatic type conversion involved only adds
const qualifiers to the type. Therefore the warnings are not legitimate.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33076



[Bug c/33076] Warning when passing a pointer to a const array to a function that expects a pointer to a non-cast one

2007-09-26 Thread joseph at codesourcery dot com


--- Comment #8 from joseph at codesourcery dot com  2007-09-26 12:38 ---
Subject: Re:  Warning when passing a pointer to a const array
 to a function that expects a pointer to a non-cast one

On Wed, 26 Sep 2007, jozef dot behran at krs dot sk wrote:

 Could you give me reference in the C standard where this is stated ? The
 section 6.7.3, paragraph 8, says nothing about C/C++ not having qualified 
 array
 types, it only says that a qualifier applied to an array type holds for the
 element type of the array type (these two are not the same things, see bug
 16602 for more discussion about the topic).

That which you quote means there is no way to put a qualifier on the array 
type because any attempt to do so puts it on the element type instead.  
That there are no qualified array types is simply the logical conclusion 
from there being no C syntax to write one.  Note not the array type in 
that paragraph.

The question of whether abstractly one might imagine a qualified array 
type in C despite the lack of syntax to describe one, and how such a type 
(notwithstanding the lack of syntax to describe it) would behave if it 
were to exist, is not an interesting one in the absence of implementation 
extensions to define such a type.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33076



[Bug c/33076] Warning when passing a pointer to a const array to a function that expects a pointer to a non-cast one

2007-09-26 Thread joseph at codesourcery dot com


--- Comment #9 from joseph at codesourcery dot com  2007-09-26 12:42 ---
Subject: Re:  Warning when passing a pointer to a const array
 to a function that expects a pointer to a non-cast one

On Wed, 26 Sep 2007, jozef dot behran at krs dot sk wrote:

 And another point: Whether C/C++ have or don't have qualified array types,
 still the difference between the const caca * and caca * types is a 
 const
 qualifier being applied to some part of the caca * base type. Therefore the
 types must be compatible when the automatic type conversion involved only adds
 const qualifiers to the type. Therefore the warnings are not legitimate.

Read the C FAQ.  You can't pass a char ** where a const char ** is 
expected either in C.  That's how the language works.

http://c-faq.com/ansi/constmismatch.html

C++ allows certain cases C doesn't that can be shown to be safe, as noted 
in that FAQ.  A proposal to make C use the C++ rules was rejected in the 
course of C99 development.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33076



[Bug c/33076] Warning when passing a pointer to a const array to a function that expects a pointer to a non-cast one

2007-09-19 Thread jbeulich at novell dot com


--- Comment #3 from jbeulich at novell dot com  2007-09-19 09:39 ---
Isn't this the same as 16602 (which I don't really understand why it was
rejected as invalid)? Also, if this *is* invalid, then what proper mechanism
does one have to express what is intended here? And why does similar code
compile warning free in C++?


-- 

jbeulich at novell dot com changed:

   What|Removed |Added

 CC||jbeulich at novell dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33076



[Bug c/33076] Warning when passing a pointer to a const array to a function that expects a pointer to a non-cast one

2007-09-19 Thread schwab at suse dot de


--- Comment #4 from schwab at suse dot de  2007-09-19 09:47 ---


*** This bug has been marked as a duplicate of 16602 ***


-- 

schwab at suse dot de changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33076



[Bug c/33076] Warning when passing a pointer to a const array to a function that expects a pointer to a non-cast one

2007-09-19 Thread joseph at codesourcery dot com


--- Comment #5 from joseph at codesourcery dot com  2007-09-19 19:54 ---
Subject: Re:  Warning when passing a pointer to a const array
 to a function that expects a pointer to a non-cast one

On Wed, 19 Sep 2007, jbeulich at novell dot com wrote:

 Isn't this the same as 16602 (which I don't really understand why it was
 rejected as invalid)? Also, if this *is* invalid, then what proper mechanism
 does one have to express what is intended here? And why does similar code
 compile warning free in C++?

Neither C nor C++ have qualified array types, only arrays of qualified 
element types, but C++ has different rules from C regarding conversions 
involving qualifiers, which allow some conversions (involving arrays or 
pointers to pointers) not allowed in C.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33076



[Bug c/33076] Warning when passing a pointer to a const array to a function that expects a pointer to a non-cast one

2007-08-15 Thread raeburn at raeburn dot org


--- Comment #1 from raeburn at raeburn dot org  2007-08-15 06:13 ---
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



[Bug c/33076] Warning when passing a pointer to a const array to a function that expects a pointer to a non-cast one

2007-08-15 Thread raeburn at raeburn 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