Re: Calling a function with a float argument modifies caller's state.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 08/21/2012 06:40 PM, Jeff B wrote:


(int)floatVarA = 0.000000            <<=== initial value 0??
On 08/22/2012 03:50 AM, Andrew Haley wrote:

The initial value is zero because there is garbage in Float Register 0.

floatVarA = 1234.000000
Now Float Register 0 contains 1234.0 .

(int)floatVarA = 1234.000000     <<=== changed
Which gets printed out.

floatVarB = 5678.000000
Now Float Register 0 contains 5678.0 .

(int)floatVarA = 5678.000000    <<=== changed again
Which gets printed out.

floatVarA = 1234.000000
etc...

Moral: undefined behaviour can do anything.

Andrew.


OK, then I guess the presence of the cast makes it OK for the compiler
to pull the bits for a variable from somewhere other than where the
variable actually is.

So, while we are at it, what other casts should I avoid?

Thanks.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux