100k X 100k data processing summary

J

James Kuyper

santosh said:
Yes. This is the only way.

And why, pray tell, would it be better to write a loop setting the array
elements to null pointers, when the very next thing the code does is
execute a loop setting the array elements to valid pointers?

I don't think the calloc() call is useful, and I don't think this
pre-loop would be useful either.
 
B

Barry Schwarz

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
 
C

CBFalconer

Barry said:
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.

Because it does nothing. A void* (returned by calloc) can be
assigned to any pointer type with automatic conversion. If
<stdlib.h> has not been included the cast just prevents the
signalling of the error on compilation, the error is still there.
And, since a pointer object can only hold pointer values, as
received from malloc and friends, a non-NULL value is totally
meaningless in there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top