Hi Dave,
I see the problem you raise, but I am not sure if there is a clean
solution.
While all arrays may be packed, this does not mean that objects are
not on aligned in general. The pointer to an integer you defined is
one such pointer that could be used to dereference aligned objects.
If the compiler were classify 'ip' as always referring to packed
array, this would be a disservice when it is used to dereference
aligned object.
It is worth pointing out that the C compiler characterises a variable
based on its deceleration and not its usage.
To incorporate your suggestion, it would also have to characterise the
variable (in this case a pointer) based on its usage. I think this is
very hard to do, if at all possible.
The compiler would have told you this is wrong -- but you said "never
mind" by the explicit cast. You think it should still warn you, but
another may retort "why do you think I made the explicit cast?"
At the risk of adding yet another dimension, I think the problem you
are alluding is very similar to subtle but potent distinction in C
between arrays and pointers.
Jaya
--- In lpc2000@yahoogroups.com, "dsidlauskas1" <dsidlauskas@...> wrote:
>
> Jaya,
>
> The "vanilla" cast is only to be treated as a byte packed cast if the
> object that is being cast is itself byte packed.
>
> In thinking about my original case, the compiler should at least warn
> since, with;
>
> char buf[]={...};
> int *ip;
>
> ip = (int *)&buf[i];
>
> the left and right side of this assignment are not of the same type,
> even though the declaration would have you think so. ip is a pointer
> to a default word aligned object, and (int *)&buf[i] is a pointer to
a
> byte aligned object. These are really not the same data types.
>
> But I'm afraid I may be getting ahead of myself here. If I'm not
> careful someone is going to smack me with the C99 spec :-).
>
> I'll stick with my original assertion that the compiler could deal
> with this issue in a more useful way than it does.
>
> Dave S.Message
Re: For C Experts
2006-03-31 by jayasooriah
Attachments
- No local attachments were found for this message.