Connecting Tech Pros Worldwide Forums | Help | Site Map

passing float to function

ayaz.ali@gmail.com
Guest
 
Posts: n/a
#1: Dec 7 '06
Hello,
I am having a problem sending float parameter to a function in another
c file with its declaration in a common header file. When I send the
float with value 1.00000000, the receiving function gets 0. I suppose
the float value gets converted to double and then back to float with
only lower half of double (i.e. 0).
I am using ANSI C declaration. Does anyone know how to fix this. I am
running it on windows at the moment but i believe gcc on linux has the
same problem.

Ayaz


Martin Ambuhl
Guest
 
Posts: n/a
#2: Dec 7 '06

re: passing float to function


ayaz.ali@gmail.com wrote:
Quote:
Hello,
I am having a problem sending float parameter to a function in another
c file with its declaration in a common header file. When I send the
float with value 1.00000000, the receiving function gets 0. I suppose
the float value gets converted to double and then back to float with
only lower half of double (i.e. 0).
I am using ANSI C declaration. Does anyone know how to fix this. I am
running it on windows at the moment but i believe gcc on linux has the
same problem.
It is impossible from your description to even hazard a guess. Passing
float 9and other floating point) variables to functions is such
meat-and-potatoes stuff that you may be the only person who can't do it.
The only thing in your post that is at all suggestive of your problem
is "with its declaration in a common header file." Wherever your
defining declaration is, it does not belong in a header. If you must,
for some reason, declare files in a header, at least declare them extern
and have a defining declaration in one of your non-header translation units.

pete
Guest
 
Posts: n/a
#3: Dec 7 '06

re: passing float to function


ayaz.ali@gmail.com wrote:
Quote:
>
Hello,
I am having a problem sending float parameter to a function in another
c file with its declaration in a common header file. When I send the
float with value 1.00000000, the receiving function gets 0. I suppose
the float value gets converted to double and then back to float with
only lower half of double (i.e. 0).
That's not how conversions work.
Quote:
I am using ANSI C declaration. Does anyone know how to fix this. I am
running it on windows at the moment but i believe gcc on linux has the
same problem.
Create and post the smallest C program
which exhibits your problem.

--
pete
Richard Bos
Guest
 
Posts: n/a
#4: Dec 8 '06

re: passing float to function


ayaz.ali@gmail.com wrote:
Quote:
I am having a problem sending float parameter to a function
You don't send parameters to functions, you pass them. You send messages
to objects, which C doesn't have (at least, not built-in).
Quote:
in another
c file with its declaration in a common header file. When I send the
float with value 1.00000000, the receiving function gets 0.
Show code. You probably either declared the function wrong (or even more
likely, not at all), or call it wrong. But show code if you want us to
tell you which.

Richard
Closed Thread


Similar C / C++ bytes