Dave, Think about whet your saying here: > ip = (int *)&buf[5]; > > should be treated by the compiler as: > > ip = (__packed int *)&buf[5]; > "should" doesn't come into it! You have explicitley told the compiler exectly how you want it treated (the "(int *)"). Now if you had one of those magic "do what I mean, not what I say" compilers, you'd be fine...... By the way, if you find that compiler, let me know! Brendan --- In lpc2000@yahoogroups.com, "dsidlauskas1" <dsidlauskas@...> wrote: > > 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@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 > > >
Message
Re: For C Experts
2006-03-31 by brendanmurphy37
Attachments
- No local attachments were found for this message.