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 08:50:28PM +0200, Hartmut Schirmer wrote:
> On Fri, 11 Aug 2000, Zack Weinberg wrote:
> >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.
> 
> This is a minor bug in the compiler. GCC gives the user the choice
> over the alignment. Suitable diagnostics should guard this feature.
> This code may work for years on a x86 box and fails if ported to
> a PPC or SPARC. With the #pragma pack() it might even be very hard
> to figure out what is wrong with the code. Am ulti target compiler
> like GCC should warn about potential problems with the non-standard
> alignment.

[... good ideas trimmed ...]

As Larry Wall would say, patches are welcome.

zw

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