Hello Dave,
I see two errors in the program that the KEIL compiler (justifiably
IMHO) does not pick up.
The first error, assignment #1 in for loop, explicitly tells the
compiler to cast to (int *) something that it will not understand as
(int *). Thus the compiler thus has no say (IMHO) in questioning this
assignment, and which will no doubt cause of unaligned access errors
in the statement immediately after.
The second error, assignment #2 in the for loop, is the proverbial
array bounds problem that compilers tradionally shy away becuase of
the need for (potentially expensive) run-time support libraries to do
this properly.
Hope this helps.
Jaya
PS: E&OE -- yahoo mail is not getting through and I have to resort to
web interface!
--- In lpc2000@yahoogroups.com, "dsidlauskas1" <dsidlauskas@...> wrote:
>
> Consider the following code:
>
> ============================
> char buf[]={1,2,3,4,5,6,7,8};
> int *ip, x[4];
>
> for (i=0; i<4; i++)
> {
> ip = (int *)&buf[i];
> x[4] = *ip;
> }
> =============================
> The Keil compiler compiles this without warning, but does not produce
> the expected (for me) result in x. The problem is that Keil uses the
> LDR instruction to effect the transfer and this is valid only on 4
> byte boundaries.
>
> GCC compiles but does give a non-aligned access warning.
>
> I believe that the compiler has enough information to use byte aligned
> transfers, and should, or at least give a warning.
>
> Anybody want to weigh in on this one.
>
> Thanks in advance for your comments.
>
> Dave Sidlauskas
>Message
Re: For C Experts
2006-03-30 by jayasooriah
Attachments
- No local attachments were found for this message.