Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: For C Experts

2006-03-31 by dsidlauskas1

Jaya,

Since the compiler knows that buf is a byte aligned object, woutldn't
it be resonable for the compiler to treat

(int *)&buf[i]

as 

(__packed int *)&buf[i]

In general, if non-naturaly aligned objects are promoted by a cast,
shouldn't, by default, the cast be of the proper non-aligned type?

BTW. Really appreciate your discussion of interupts on your web site.

Dave


--- In lpc2000@yahoogroups.com, "jayasooriah" <jayasooriah@...> wrote:
>
> Dave,
> 
> To us the unaligned pointer assignment is obvious when we look at it
> in context.
> 
> To the compiler, that line alone is not enough to say that assignment
> is invalid.  For example, it is a perfectly valid if the value of "i"
> is a multiple of four in your example.
> 
> Sometimes pointers are used to pass information which are not valid
> pointers (but as an escape to the norm) and these pople would be
> crossed if compilers did not allow them to do this.
> 
> Jaya
> 
> --- In lpc2000@...m, "dsidlauskas1" <dsidlauskas@> wrote:
> 
> > The information to the compiler is in the line:
> > 
> >  ip = (int *)&buf[i];
> > 
> > Where it should be clear that the pointer is to an unaligned int.
> > 
> > Dave S.
>

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.