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]

Re: Alignment option


On Fri, Aug 11, 2000 at 10:50:57AM -0700, Mike Stump wrote:
> > From: "Philippe Bonneau" <phbonneau@hotmail.com>
> > To: gcc@gcc.gnu.org
> > Date: Fri, 11 Aug 2000 15:39:34 CEST
[snip example]
> > testStruct s;
> > test(&s.var);
> 
> This is a bug in the compiler.  The type of &s.var isn't double *, and
> should not implicit convert to a double* either.  What it is, is a
> pointer to an unaligned double.  It is a type violation to use a
> double value when that double value is actually an unaligned double.
> The only access permitted is by way of an unaligned double.

I don't know about C++, but the type system in standard C does not
distinguish between unaligned and aligned pointers.  &s.var in the
example is a pointer to double, which happens to not fulfill the
alignment requirements of the type.  Therefore dereferencing the
pointer produces undefined behavior.

IMO, there is no bug in the compiler.

> > Even when I tried to compile with -munaligned-doubles, it didn't
> > resolve the problem. Which flag must be set?
> 
> No flag, the code is wrong as well as the compiler.

This isn't a helpful answer.

You've deliberately overridden the alignment rules of the SPARC
architecture for the 'testStruct' structure.  You cannot do nearly as
many things with such a structure as you can with a normal one.  It
should be safe to set and examine s.var directly, but not via a
pointer.  It should also be safe to pass around a pointer to the
entire structure, or copy it by structure assignment.  If any of those
things do not work, then that might be a bug in the compiler.

-munaligned-doubles is documented confusingly, but I believe it means
to say it only affects how the compiler treats local variables and
arguments to functions.  It is for compatibility with obsolete
compilers and hardware, and should not be used.

zw

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