Dear Tzahi, I think that's the problem is that you can't delete members from an array -- even if it was created dynamically, because the memory allocation here is allocated continuously as an "ordinary" static array -- (the created dynamic memory you issued is an array for every thing). You can reallocate the array but not delete members from it. This issue is related to C language and not to Linux.
Thanks & best regards, Jo. -----Original Message----- From: Haifux - Haifa Linux Club [mailto:[EMAIL PROTECTED] On Behalf Of Orna Agmon Sent: Wednesday, March 09, 2005 10:03 AM To: Ido Barnea Cc: Tzahi Fadida; Haifa Linux club Subject: RE: [Haifux] c with a spoon and pointer arithmetic The question was: what is the exact type of error created? Orna. On Wed, 9 Mar 2005, Ido Barnea wrote: > Date: Wed, 9 Mar 2005 09:36:23 +0200 > From: Ido Barnea <[EMAIL PROTECTED]> > To: Tzahi Fadida <[EMAIL PROTECTED]>, > Orna Agmon <[EMAIL PROTECTED]> > Cc: [email protected] > Subject: RE: [Haifux] c with a spoon and pointer arithmetic > > Don't know what was said in the lecture, but I guess > it was an example for something that shouldn't be done. > You can't use free with a pointer to the middle of an > allocated area, it causes segmantation fault (as you noticed). > Ido > > > -----Original Message----- > > From: Haifux - Haifa Linux Club > > [mailto:[EMAIL PROTECTED] Behalf Of Tzahi Fadida > > Sent: Wednesday, March 09, 2005 2:49 AM > > To: 'Orna Agmon' > > Cc: [email protected] > > Subject: [Haifux] c with a spoon and pointer arithmetic > > > > > > As we talked about in the c with a spoon lecture, I tried the > > pointer arithmetic and then free and at least for me it didn't > > work. > > gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) > > > > [EMAIL PROTECTED]:~]$ gcc nis2.c > > [EMAIL PROTECTED]:~]$ ./a.out > > char y[0] a > > char y[1] b > > char y[2] c > > char y[3] d > > Segmentation fault (core dumped) > > > > #include <stdio.h> > > #include <stdlib.h> > > main(){ > > char *y = (char *)malloc(4*sizeof(char)); > > char *x = y + 2; > > y[0]='a'; > > y[1]='b'; > > y[2]='c'; > > y[3]='d'; > > printf("char y[0] %c\n", y[0]); > > printf("char y[1] %c\n", y[1]); > > printf("char y[2] %c\n", y[2]); > > printf("char y[3] %c\n", y[3]); > > > > free(x); > > > > printf("char y[0] %c\n", y[0]); > > printf("char y[1] %c\n", y[1]); > > // printf("char y[2] %c\n", y[2]); > > // printf("char y[3] %c\n", y[3]); > > > > exit(EXIT_SUCCESS); > > } > > > > Regards, > > tzahi. > > > > WARNING TO SPAMMERS: see at > > http://members.lycos.co.uk/my2nis/spamwarning.html > > > > > > > > -------------------------------------------------------------- > > ------------ > > Haifa Linux Club Mailing List (http://www.haifux.org) > > To unsub send an empty message to [EMAIL PROTECTED] > > > > > > > > -------------------------------------------------------------------------- > Haifa Linux Club Mailing List (http://www.haifux.org) > To unsub send an empty message to [EMAIL PROTECTED] > > > Orna. -- Orna Agmon http://ladypine.org/ http://haifux.org/~ladypine/ ICQ: 348759096 -------------------------------------------------------------------------- Haifa Linux Club Mailing List (http://www.haifux.org) To unsub send an empty message to [EMAIL PROTECTED] -------------------------------------------------------------------------- Haifa Linux Club Mailing List (http://www.haifux.org) To unsub send an empty message to [EMAIL PROTECTED]
