[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: strange behaviour of -O2 optimization



On Tue, Jan 06, 2004 at 12:02:29AM +0100, Nicolas François wrote:
> Hello,
> 
> I had a look at the debian bug #225313. This bug only raise raise when
> optimization is used. I've submitted a patch, but would like to
> understand if gcc behaviour was normal.
> 
> 
> I've selected a sample of code that should raise the same issue:
> 
> =======================================================================
> typedef unsigned long word;
> typedef unsigned long long dword;
> 
> #define LOW_WORD(x) (word)(x)
> #define HIGH_WORD(x) (*(((word *)&(x))+1))

You can't do this.  I recommend you google for "strict aliasing" for a
number of good discussions of the problem.

> gcc warn about:
>     test.c: In function `test':
>     test.c:14: warning: dereferencing type-punned pointer will break
>     strict-aliasing rules
> Is it related?

Yes.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer



Reply to: