Yahoo Groups archive

Lpc2000

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

Message

Re: For C Experts

2006-03-30 by jayasooriah

Dave,

The satement "x[4] = ..." trashes memory where the the fifth element
of the array "x[]" would normally exist, because you have declared it
as "x[4]" which means it has only four elements.  Hence the array
bound problem.

Jaya

--- In lpc2000@yahoogroups.com, "dsidlauskas1" <dsidlauskas@...> wrote:
>
> I don't think its out of bound. X[4] is the 5th location in the
> buffer, &x[4] is it's address, and there are 4 bytes declared from
> theis address (5, 6, 7, 8).
> 
> Anyway, for the purpose of this example initialize the first 20
> locations of buf.
> 
> --- In lpc2000@yahoogroups.com, David Hawkins <dwh@> wrote:
> >
> > dsidlauskas1 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;
> > >     }
> > 
> > Er, given the fact that x is of length 4,
> > the statement x[4] = *ip is actually out-of-bounds.
> > 
> > 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.