Mail Archives: djgpp/1997/01/03/10:07:56
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 -