DR#236 analysis

Paul Schlie schlie@comcast.net
Sat Dec 4 00:36:00 GMT 2004


> Geoff Keating writes:
> I see. Yes, that's not what I meant. In this case, the type of the malloc-ed
> memory is 'struct elf_link_hash_entry', and that's what's not allowed to
> change; what I want prohibited is code like:
>
>  void * mem = malloc (max (sizeof (int), sizeof (float));
>  *(int *)mem = 1;
>  *(float *)mem = 2.0;
>
> where the top-level type of the memory changes.

What's wrong with conservatively assuming that a pointer may alias
cumulatively any object type if ever explicitly dereferences, where
a dereferenced union is equivalent to it's cumulative set of types.)

 (i.e. logical equivalent to your example, mem :: int*, float*, or void*)

Where then if someone wants to take advantage of potential optimizations;
they should use pointers conservatively, and ideally explicitly declare
them as not being aliased if enabled by the language.

As it would seem to be better to be safe than sorry, and not unnecessarily
restrict programmers to accomplish what they want to do, with the
understanding that there may be consequences to their decisions.




More information about the Gcc mailing list