Hi,
What would cause calloc() to return a NULL pointer?
calloc/malloc is unable to give you continous memory in the requested
size.
Is the system simply out of memory?
Maybe, maybe not.
The system may have some TB available but the process your calloc is
in has eaten all memory the system will give it.
By that: calloc is alöways useless except you are allocating real char
arrays.
calloc fills the memory block with binary 0. But there is no guaratee
that ponters floatingpoint variables or even structs are valid when
set to binary 0 chars. Character arrays are the only guaranteed to be
ready for usage when filled with binary 0. Pointers are not,
floatingpoint variables are not and even structs are not. On some
environments it may work, on others it will crash depending on the
underlying hardware.
So use malloc instead and initialise the variables with theyr typed
form of 0, e.g 0.0, or 0. calloc has no idea which kind of 0 the
variable needs, the compiler does, so it will convert a simple 0 to
its real type (0.0, (void*)0,...) for you.
--
Tschau/Bye
Herbert
Visit
http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!