This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: legal ruling on aliasing
- From: Geoff Keating <geoffk at geoffk dot org>
- To: bkorb at veritas dot com
- Cc: Rob Browning <rlb at defaultvalue dot org>, gcc at gcc dot gnu dot org
- Date: 19 May 2003 14:47:52 -0700
- Subject: Re: legal ruling on aliasing
- References: <3EC94B67.430075F4@veritas.com>
Bruce Korb <bkorb@veritas.com> writes:
> In another list, the issue was raised whether or not these
> two constructs are completely equivalent under the laws of
> aliasing:
>
> stumble_t s;
> function( (mumble_t*)(void*)&s );
>
> versus:
>
> stumble_t s;
> {
> void* v = (void*)&s; // scope constrained to following:
> function( (mumble_t*)v );
> }
Yes, they are. They're both exactly the same as
stumble_t s;
function ( (mumble_t *)&s);
for aliasing purposes.
> In other words, would the compiler be allowed to presume that
> function() did not modify `s'? Particularly, could it make
> such an assumption in one case and not the other?
No, it can make no such assumption in either case, because 'function' could be:
void function (mumble_t *x)
{
stumble_t * sp = (stumble_t *)x;
*sp = *sp + 1;
}
--
- Geoffrey Keating <geoffk@geoffk.org>