How? Certainly during debugging it makes perfect sense to zero a new
block if for nothing else than examining the memory. In the real world
that is.
How is the cast worse than useless? It can suppress the otherwise
mandatory diagnostic if there is no prototype in scope for calloc
which would lead to undefined behavior. Your point about zeroing
memory is not unreasonable as long as the programmer realizes that
this is not the same as assigning NULL to the elements.
I need this explaining once again.
ptr = (float*) *fltPointer++;
If its all bit 0s then surely assignment of 0 will cast to the "real
null for that pointer type".
I'm sorry but this needs to be expanded. Is fltPointer all bits 0 or
is *fltPointer all bits 0? Assuming ptr is a float*:
If the first case, then the statement invokes undefined
behavior on all systems where all bits 0 is a NULL pointer value. On
systems where all bits 0 points to valid memory, it will extract the
float at whatever address all bits 0 represents (probably address 0)
and attempt to convert that value to a float*. Converting an integer
value to a pointer is implementation defined but I don't recall seeing
anything about converting a floating point value to a pointer.
If the second case, and if all bits 0 is a valid
representation of 0.0f, then I would expect ptr to be assigned the
NULL value for a float*, notwithstanding the last sentence in the
preceding paragraph..
Other than as a confusion factor, why did you throw in the ++? What
does it contribute to the discussion?
Or would you actually advocate writing your own loop applying a "null"
for float * to the memory block?
If you need the pointers initialized to NULL and are trying to write
portable code, then absolutely. On the other hand, if the very next
block of code assigns new values to the pointers, then neither
approach seems beneficial.
Remove del for email