On Thursday 10 March 2005 20:13, Diego Iastrubni wrote:
> Shlomi Fish wrote:
> >On Thursday 10 March 2005 16:17, Diego Iastrubni wrote:
> >>Shlomi Fish wrote:
> >>>mem[102] = 'c'.
> >>>
> >>>>SEGFAULT! the allocated memory is found at memory 100-103. Bad Thazi!
> >>>
> >>>No, it's OK so far.
> >>
> >>how come? he is refering to memory which is not allocated? lets ignore
> >>the issue that the amount of allocated memory can be also 20 as someone
> >>sayd before...
> >
> >Because he was mallocing four bytes for x, and then putting information in
> >x[0] to x[3].
>
> y[0] to t[3]....
>
Right, that's y[0] to y[3]. That was a typo. But it was perfectly OK to assign
to y[2], because 4 bytes were allocated for y. Reading from the code:
<<<
char *y = (char *)malloc(4*sizeof(char));
char *x = y + 2;
y[0]='a';
y[1]='b';
y[2]='c';
y[3]='d';
>>>
Regards,
Shlomi Fish
> thats x[0] and x[1], x[2] and x[3] are not defined... or out of range
>
>
> --------------------------------------------------------------------------
> Haifa Linux Club Mailing List (http://www.haifux.org)
> To unsub send an empty message to [EMAIL PROTECTED]
--
---------------------------------------------------------------------
Shlomi Fish [EMAIL PROTECTED]
Homepage: http://www.shlomifish.org/
Knuth is not God! It took him two days to build the Roman Empire.
--------------------------------------------------------------------------
Haifa Linux Club Mailing List (http://www.haifux.org)
To unsub send an empty message to [EMAIL PROTECTED]