This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: strict aliasing


On Wed, Nov 07, 2007 at 04:06:11AM +1100, skaller wrote:
> On Tue, 2007-11-06 at 07:49 -0800, Joe Buck wrote:
> > Now it appears that you want to make some kind of intermediate assumption
> > (semi-strict aliasing?), where pointers of different types are allowed to
> > alias while ints can't alias with pointers.  
> 
> Yes. I want layout compatible types to be allowed to alias but
> not others. In other words, where the access would be valid
> provided it isn't optimised, don't optimise it. But where
> the access would not be valid, optimise away.

The problem is that this doesn't appear to be what anyone else wants.
Your rule would still break some existing code that needs
-fno-strict-aliasing, but allows some aliasing that the C standard
does not allow.  It seems to be a rule that is tailored to your
personal programming style.

> In C++ this is essential because constructable types cannot
> be aliased in a union. This problem doesn't arise like that
> in C.

One way to do this in C++ is to derive the different representations that
might appear in your "union" from a common base class, and use placement
new to lay them out.  There are probably other ways as well.  Your
hairy casts are, IMHO, quite risky.

> BTW: yes I understand I ask for something gcc may not be
> doing, I'm not asking for a change, just to understand
> what it actually does.

You are misusing C++, I'm afraid, and there are no promises that
some day a new optimization won't break your code.  I suggest
consulting a C++ experts' forum, like comp.lang.c++.moderated,
for ideas on how to do what you want to do in standard C++.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]