delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/20/21:26:03

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Re-Mallocing an array...
Date: Wed, 20 May 1998 18:45:25 -0400
Organization: Two pounds of chaos and a pinch of salt.
Lines: 25
Message-ID: <35635D05.69D@cs.com>
References: <6jv6s8$kn1 AT nnrp4 DOT farm DOT idt DOT net>
NNTP-Posting-Host: ppp141.cs.net
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Chia wrote:
> 
>   foo = (int *)malloc( sizeof(int) * 10);
> 
> And then I want to change it to hold 20 ints.  So, I figured I'd free it and
> then remalloc it.
> 
>   free(foo);
>   foo = (int *)malloc( sizeof(int) * 20);
> 
> but this crashes.  How do I do this, then?

How exactly does this crash and where?  Did you make sure to check that
the original foo pointer was in fact allocated by testing for NULL?  How
are you declaring and using foo in your code?  We need to see actual
example code that doesn't work.  It would also be nice to see a symified
crash traceback (see chapter 9.2 of the DJGPP FAQ).

-- 
---------------------------------------------------------------------
|      John M. Aldrich       |"Men rarely (if ever) manage to dream |
|       aka Fighteer I       |up a god superior to themselves. Most |
|   mailto:fighteer AT cs DOT com   |gods have the manners and morals of a |
| http://www.cs.com/fighteer |spoiled child."    - Lazarus Long     |
---------------------------------------------------------------------

- Raw text -


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