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





>From: Hartmut Schirmer <hartmut.schirmer@arcormail.de>
>Reply-To: hartmut.schirmer@arcormail.de
>To: Zack Weinberg <zack@wolery.cumb.org>
>CC: gcc@gcc.gnu.org, phbonneau@hotmail.com
>Subject: Re: Alignment option
>Date: Fri, 11 Aug 2000 20:50:28 +0200
>
>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.

Sure, GCC should warn, but such code works when compiled with CC. The 
resolution should be something like that : warnings on all platform, and a 
specific flag for SPARC implementation to resolve the problem.


>
>Some possible ways to deal with the & operator on an element
>of a packed structure:
>
>If the packed alignment of the member fullfills all alignment
>requirements of the type, no action ist needed, but a warning may be
>given (at -W ?)
>
>If the alignment is less then the default alignment
>- a warning should be given if performance will degrade
>   (eg. on x86) but code will work
>   (potential slow, portability affected)
>
>- a warning should be given if the total alignment is unknown
>   (potential dangerous, portability affected)
>
>- a warning/an error should be given if GCC knows the code won´t work
>
>Hartmut

In any case, thanks for your help.
Philippe
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com


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