Yahoo Groups archive

Lpc2000

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

Message

Re: For C Experts

2006-03-31 by dsidlauskas1

Jaya,

I don't think I'm asking it to connect the two statements.

What I'm expecting it to do is to recognize that buf is a byte packed
object (the defalt for the compler)and when casting byte packed
objects the compiler should cast them to other byte packed objects.

in otherwords;

char buf[10];
int ip*;

ip = (int *)&buf[5];

should be treated by the compiler as:

ip = (__packed int *)&buf[5];

and this is because char buf[10] is a byte packed object for this
compiler.

Dave


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