Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 667
Adam Lee Avatar asked Jul 25 '11 23:07

Adam Lee


1 Answers

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);
like image 77
unkulunkulu Avatar answered Oct 04 '22 17:10

unkulunkulu