Re: printf("%d",float)



Richard Heathfield wrote:
Jack Klein said:

On Wed, 31 Oct 2007 01:15:33 +0000, Richard Heathfield
<rjh@xxxxxxxxxxxxxxx> wrote in comp.lang.c:

<snip>
You are wrong in thinking that %d is the appropriate format specifier
for a float, and you are wrong in thinking that you can meaningfully
cast the address of a float into the address of an int.
You were right in the first pronouncement, not necessarily so in the
second. The result of casting a pointer to an object or incomplete to
a pointer to any other object or incomplete type, is undefined if the
pointer is not suitably aligned for the second type, but well defined
if there is no alignment error. Of course, dereferencing that pointer
is completely undefined.

Right, which is why I consider the conversion meaningless.

So conversion to void * is always meaningless, because no void * can be dereferenced?

Phil

--
Philip Potter pgp <at> doc.ic.ac.uk
.



Relevant Pages

  • Re: weird code.
    ... never seen this kind of declaration ever. ... The variable data is a float pointer? ... array of 16384 float objects. ...
    (comp.lang.c)
  • Re: Help a beginner - function with pointer ...
    ... i thought (float *) T would be appealing to ... The result is the value obtained by converting the ... `T' refers to a one-dimensional array whose elements are also ... using a pointer to the array's first element. ...
    (comp.lang.c)
  • Re: new foo[42]
    ... > First question: ... 42 type 'float' objects, and returns the address ... value in the pointer object 'foo'. ... The first form above dynamically allocates an array (which ...
    (comp.lang.cpp)
  • Re: is it safe to zero float array with memset?
    ... >> Not if you then try to use the value as a float or as a pointer. ... >> load it into an address register (no dereference needed). ... If it's a matter of the implementation itself, *IT'S NOT SAFE*. ...
    (comp.lang.c)
  • Re: Simple question, err... I think
    ... It's meaningless to then direct me to look at the code. ... quality of the code it felt safe to assume a leak :-)). ... Set B(Set l, int n, Set r) ... /All/ 'return' statements in this function return a pointer to a freshly ...
    (comp.programming)