Returning a 1.0f gives me 1065353216
I have a C function that returns a type float
.
When the function returns 1.0f
, the receiver sees 1065353216
, not 1.0
.
What I mean is, the following:
float Function()
{
return 1.0f;
}
float value;
value = Function();
fprintf(stderr, "Printing 1.0f: %f", value);
Displays:
开发者_开发技巧1065353216
But not:
1.0
You define your function in one source file and call it from another one not providing the signature making the compiler think that the signature is int Function()
, which leads to strange results.
You should add the signature: float Function();
in the file where the printf
is.
For example:
float Function();
float value;
value = Function();
fprintf(stderr, "Printing 1.0f: %f", value);
Double check your work, as your implementation is correct.
Evidence: http://codepad.org/QlHLEXPl
My turn to guess the problem:
You are either:
- editing the source code without saving it
- editing one file but compiling and running another one
- editing and compiling one file but running another one
- doing something even more complicated but similar :)
精彩评论