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

I mean the following:

float Function()
{
    return 1.0f;
}

float value;
value = Function(); 
fprintf(stderr, "Printing 1.0f: %f", value);

Conclusion:

1065353216

But not:

1.0
+5
source share
3 answers

You define your function in one source file and call it from another without providing a signature so that the compiler considers that signature int Function(), which leads to strange results.

You must add the signature: float Function();to the file where it is located printf.

For instance:

float Function();
float value;
value = Function(); 
fprintf(stderr, "Printing 1.0f: %f", value);
+15
source

Double check your work, as your implementation is correct.

: http://codepad.org/QlHLEXPl

+4

My turn is to guess the problem:

You too:

  • editing source code without saving
  • editing one file, but compiling and starting another
  • editing and compiling one file, but running another
  • do something even more complicated but similar :)
0
source

All Articles