Mail Archives: djgpp/1997/01/04/08:27:17
Andreas Vernersson <hubb AT freenet DOT hut DOT fi> wrote:
: I was programming on a "big" project now, when i sometimes began getting
: Floating point exeptions at random positions in the code. (Reported
: 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?
malloc doesn't clean the memory it allocates, while calloc does. If
you are using floats that are filled with random values (probably from
previous mallocs), chances are that you get a FPE sometimes. When you
use calloc, the memory will filled with zeroes, which also make up 0.0
floats and doubles (and NULL pointers as well), but this isn't a very
good idea wrt. to portability, since it is not guarantueed that the
CPU represents 0.0 with zeros (any I have come across do, however).
bye, Alexander
--
Alexander Lehmann, | "On the Internet,
alex AT hal DOT rhein-main DOT de (MIME, NeXT) | nobody knows
lehmann AT mathematik DOT th-darmstadt DOT de (MIME) | you're a dog."
<URL:http://home.pages.de/~lehmann/>
- Raw text -