Is this a bug?

Stanley Friesen sarima at tdatirv.UUCP
Wed Sep 5 02:15:46 AEST 1990


In article <5690 at quanta.eng.ohio-state.edu> rob at raksha.eng.ohio-state.edu (Rob Carriere) writes:
>I have found what I suspect is a bug in the C compiler I am using, but I would
>like confirmation before I start bad-mouthing.   :-)
 
>typedef union ut { T1 e1; T2 e2 } ut;
>void f( int const p1, ut const p2 );
>void foo( void )
>{
>   int i;   ut u;
>   ...
>   f( i, u );      /* ERROR: typemismatch in parameter p2 in function f */
>   ...
>}
 
>Calling it like so _does_ work
 
>   f( i, *(ut const *)&u );
 
Hmm , it certainly looks rather odd.  If the compiler is not broken, it is at
least flaky - it appears to be treating unions differently than ints.  This
is, at the very least, inconsistant.

I would like to say that it is also wrong, the 'const' stuff in the prototype
can have no effect in this case because parameters are passed by value, and
are thus copied.  Thus it seems that this 'outer' const should be ignored.
(If p1 and p2 were pointers this would be different).

Unfortunately I cannot find anyplace in the standard which actually specifies
my point of view.  I though I had seen such a passage, but I cannot find it.
(Perhaps it was present in a prior draft and deleted in the final)



More information about the Comp.lang.c mailing list