[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Segmentation fault



I believe this is the code that was getting me into trouble, but it could be
elsewhere

    fscanf (file, "%s", Title);
    fscanf (file, "%d %d %d %d %d %d", &m, &n, &it, &LT, &EQ, &GT);

I was always uncomfortable with the notation esthetically, so I took
advantage of the occasion to change all the i/o to stream style
Once I got rid of "using namespace" it ran fine

Don't go away. I'll be back whining about some other problem!

Thanks, dancer. BTW, what's wrong with your code sample? I can see this is
going to be daunting!

David



----- Original Message -----
From: Junichi Uekawa <ti0113@mail4.doshisha.ac.jp>
To: <davidturetsky@email.msn.com>
Cc: <petdr@cs.mu.OZ.AU>; <debian-user@lists.debian.org>
Sent: Sunday, February 13, 2000 9:56 PM
Subject: Re: Segmentation fault


> On Sun, 13 Feb 2000 03:45:55 -0800, "davidturetsky"
<davidturetsky@email.msn.com> was crying out from somewhere
>   about: Re: Segmentation fault
>
> davidturetsky> It looks as though I was running into problems when trying
to scan an input
> davidturetsky> file using c notation which is less efficient of memory, so
I'm in the
> davidturetsky> process of revising all of the I/O to use c++ resources.
Still, it comes as
> davidturetsky> a surprise, but I'm very early on the gcc learning curve
>
>
> Reading this I am wondering if you actually did allocate memory for the
variables, or even did you do the right thing?
>
> for example, getting input for a double with scanf will require you doing
something like
>
> double a;
> scanf("%g", &a);
>
> You can even do double a; scanf("%g", a); and it might still work on MS
compiler, it won't on gcc.
>
>
> That was my personal experience migrating my own code.
> I found many invalid pointers in my code.
> MSC seems to be very "relaxed" in handling invalid pointers.
> Linux is very harsh and kills your app with a segfault as soon as you try
to
> access it.
>
> For example, this code segfaults on Linux, which used to work perfectly
fine on MSC:
>
>
> char * bitsofmemory = malloc (BIG_SIZE); FILE*f =fopen(FILENAME,
ATTRIBUTE);
> if (!(bitsofmemory && f)) {
>    free(bitsofmemory); fclose(f) /* try to clean up and it dies...*/
>    return ERROR;
> }




Reply to: