473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

passing float to function

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

Dec 7 '06 #1
3 5921
ay******@gmail.com wrote:
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.

Dec 7 '06 #2
ay******@gmail.com wrote:
>
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.
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
Dec 7 '06 #3
ay******@gmail.com wrote:
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).
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
Dec 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: news.tiscali.dk | last post by:
This might be a really simple question, but here goes: How can I pass an array to a function and have the function put values into that array? Some code to clearify (mat is a matrix class) float...
15
by: Chris Readle | last post by:
Hi all, Somewhat new to C and I'm getting the following error from my latest code. Here's the warning I'm getting: chris_readle_project3_assignment3.c: In function `main':...
3
by: ehabaziz2001 | last post by:
I know one of the pointer benefit is that we can return more than one value from a function . The down program has an error that I can not discover . That is the call of the function : The Call:...
2
by: Steve Turner | last post by:
I have read several interesting posts on passing structures to C dlls, but none seem to cover the following case. The structure (as seen in C) is as follows: typedef struct tag_scanparm { short...
17
by: Christopher Benson-Manica | last post by:
Does the following program exhibit undefined behavior? Specifically, does passing a struct by value cause undefined behavior if that struct has as a member a pointer that has been passed to...
5
by: mshaaban | last post by:
Hello, In my code I have a large static 2D arrays defined as: code: #define LONMAX 1440 #define LATMAX60 480 void main (int argc, char *argv)
2
by: johnsonbl | last post by:
Hello, I am new to C++ and am struggling with the application of passing by reference. I think I understand the concept, but I can't get the output I want from my code. Specifically, in my code...
8
by: Ruben | last post by:
error: passing `const Weight' as `this' argument of `float Weight::wgt()' discards qualifiers seems to be some sort of standard error format that I'm not understanding. I have code that...
1
by: Fizzics | last post by:
This is my first post here at Bytes. I have been trolling it, mostly with the help of Google searches, for some time now. I have done about all of the searching and reading that I really know how to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.