Yahoo Groups archive

Lpc2000

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

Message

Re: For C Experts

2006-03-31 by jayasooriah

Dave,

I think what you are asking of the compiler is to connect the two
statements in the for() loop.  Compilers do not have this capability.
 Even if it did, it would have to also consider the for() statement
too, as your code would be legitimate if the for() statement was:

>  for (i = 0; i < ...; i += 4)

A purist would argue is that there is nothing wrong with the pointer
assignment given the explicit cast.  The error occurs only if (and
when) the pointer is dereferenced at runtime.

Making it a packed array on these grounds may not be what the
programmer intended.  Besides, packed array methods involve
implementation issues.

GCC was kind enough to allude you to the possibility of such an event
ocurring.  Note that it too did not make the relationship between the
two statements.  If it did, it would report an error, not a warning.

Jaya

--- In lpc2000@yahoogroups.com, "dsidlauskas1" <dsidlauskas@...> wrote:
>
> 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

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.