cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/23/02:01:03

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Program Crashes!!! Please help! Memory errors!!!
Date: Tue, 23 Jun 1998 00:08:01 -0400
Organization: Two pounds of chaos and a pinch of salt.
Lines: 48
Message-ID: <358F2A21.525A5F2F@cs.com>
References: <358e8ecb DOT 0 AT news2 DOT ibm DOT net>
NNTP-Posting-Host: ppp148.cs.net
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Sal wrote:
> 
> OK....  I wrote this little program to sort a set of names and corresponding
> numbers.  It compiles fine... but when I run it it crashes.  It usually
> crashes in the middle of the data inpput part.  It tells me "Exiting due to
> signal SIGSEGV       General Protection Fault at eip=000058dc ........".
> Sometimes it gets past the data input part and gives me an "out of memory"
> error.  Sometimes it just prints out a bunch of garbage and hangs.  I'm new
> to C++ so excuse my ignorance of these things.  Whenever I used to program
> in Pascal I never had any type of memory problems...

That's because Pascal protects programmers against things like writing
past array boundaries.  Make the following change in main() and your
program should work:

>  string datast[num-1];
>  int data[num-1];

  string datast[num];
  int data[num];

Some other tips:

 - There should be no space after the # in a preprocessor directive.
 - In a for loop that goes from 0 to n-1, the clearest statement is
thus:

   for ( int i = 0; i < num; i++ )

   not

   for ( int i = 0; i <= num - 1; i++ )

 - void is an illegal return type for main().  See chapter 11 of the
comp.lang.c FAQ (http://www.eskimo.com/~scs/C-faq/top.html) for more
information.
 - Always compile programs with at least the flags '-Wall' and '-O'; the
compiler can catch lots of mistakes if you let it.

Hope this helps!

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I  |     mailto:fighteer AT cs DOT com     |
| "Starting flamewars since 1993"  |   http://www.cs.com/fighteer/  |
|  *** NOTICE ***  This .signature |       ICQ UIN#:  7406319       |
|  is generated randomly.  If you don't like it, sue my computer.   |
---------------------------------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019