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

Jeff B a.GNUbie@myLetters.US
Wed Aug 22 14:07:00 GMT 2012


>> 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.



More information about the Gcc-help mailing list