Yahoo Groups archive

Lpc2000

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

Message

Re: [lpc2000] For C Experts

2006-03-30 by Robert Bacs

I guess you used an out of bound index for array x :)

x[4] - array with four elements

So x[3] is the last element, and x[4] will be
overwrite 
the stack or some global data if the x array is
declared as global.

Regards,
Boby

--- 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
> 
> 
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com

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.