From: Alexander Lehmann Newsgroups: comp.os.msdos.djgpp Subject: Re: Calloc & Malloc Date: 4 Jan 1997 12:20:13 GMT Organization: Technische Hochschule Darmstadt Lines: 25 Message-ID: <5alhtt$svt@rs18.hrz.th-darmstadt.de> References: <1 DOT 5 DOT 4 DOT 16 DOT 19970103144936 DOT 0e97301e AT freenet DOT hut DOT fi> NNTP-Posting-Host: fb0404.mathematik.th-darmstadt.de To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Andreas Vernersson 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."