www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/03/10:07:56

From: kagel AT quasar DOT bloomberg DOT com
Date: Fri, 3 Jan 1997 09:43:44 -0500
Message-Id: <9701031443.AA17483@quasar.bloomberg.com >
To: hubb AT freenet DOT hut DOT fi
Cc: djgpp AT delorie DOT com
In-Reply-To: <1.5.4.16.19970103144936.0e97301e@freenet.hut.fi> (message from Andreas Vernersson on Fri, 3 Jan 1997 14:49:13 +0100 (MET))
Subject: Re: Calloc & Malloc
Reply-To: kagel AT dg1 DOT bloomberg DOT com

   Errors-To: postmaster AT ns1
   Date: Fri, 3 Jan 1997 14:49:13 +0100 (MET)
   X-Sender: verner AT freenet DOT hut DOT fi
   X-Mailer: Windows Eudora Light Version 1.5.4 (16)
   Mime-Version: 1.0
   Content-Transfer-Encoding: quoted-printable
   From: Andreas Vernersson <hubb AT freenet DOT hut DOT fi>
   Content-Type: text/plain; charset="iso-8859-1"
   Content-Length: 656

   I was programming on a "big" project now, when i sometimes began getting
   Floating point exeptions at random positions in the code. (Reported=20
   by symify). I double and tripplechecked the code but i couldn't find
   anything strange. I was using malloc to allocate mem then, but i got
   suspicius and changed all malloc's to calloc's and everything worked
   exactly as i wanted. So.. whats the difference between malloc
   and calloc, or is it some known "feature" of malloc?

   ps. i was not allocating much memory, just a couple of kb. It was
   a linked list with some arrays of floats inside.
   /andreas vernersson - Ume=E5, Sweden - hubb AT freenet DOT hut DOT fi - IRC: hubble

Calloc() zero's out the memory it returns.  Malloc() does not.  If you used
malloc() to allocate floats and doubles and did not initialize the memory to
zeros (or the floating point array elements to some reasonable values) the
memory has garbage in it and the floating point exceptions are to be expected.

-- 
Art S. Kagel, kagel AT quasar DOT bloomberg DOT com

A proverb is no proverb to you 'till life has illustrated it.  -- John Keats

- Raw text -


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