Reputation: 3003
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
Upvotes: 5
Views: 2950
Reputation: 11922
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);
Upvotes: 15
Reputation: 32933
My turn to guess the problem:
You are either:
Upvotes: 0
Reputation: 33197
Double check your work, as your implementation is correct.
Evidence: http://codepad.org/QlHLEXPl
Upvotes: 4