--- In [email protected], "Brett McCoy" <[EMAIL PROTECTED]> wrote:
>
> On Tue, Sep 9, 2008 at 1:29 PM, kumars <[EMAIL PROTECTED]> wrote:
> >
> > Could anyone tell me why the piece of code below is giving
segmentation
> > fault, and how to correct this.....
> >
> > #include <stdio.h>
> >
> > #define buffer_size 2000000000
> > #define num_writers 300
> > #define num_readers 500
> >
> > int main()
> > {
> >        char *ptr;
> >        char *shmptr[num_writers];
> 
> You declare an array of pointers here...
> 
> >        int i, numr, numw, nump;
> >
> >        unsigned long cksum = 0;
> >
> >        numr = nump % num_readers;
> >        numw = nump - numr;
> >        numw = numw / num_readers;
> >        ptr =  shmptr[numw];
> 
> But then here you access a member of this array without allocating
> memory for any of the pointers in the array.... that would be first
> guess. You also don't put any data into shmptr (which you can't do
> until you allocate memory)

Also  nump is uninitialized, which writes unknown data in numr and numw.

Thanks and Regards,
Saurabh

Reply via email to