473,800 Members | 2,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5959
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
34027
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 m; mat = matX * matZ * matT; mat.getElements( m ); Render.setMeshTransform( m ); In my matrix class I have
15
9355
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': chris_readle_project3_assignment3.c:23: warning: passing arg 1 of `displaySales' from incompatible pointer type And here is the code in question:
3
1519
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: /*---------*/ weeks_rental ( & customer , & rentdue , &rent_per_week ); The Function:
2
4845
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 cmd; short fdc; WORD dsf; short boxcar; short average; short chan_ena;
17
2815
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 free()? #include <stdlib.h> struct stype { int *foo; };
5
2410
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
1193
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 below, I am trying to return the number of coins, but I am returning the address locations instead (I think). I would appreciate any help giving me a hint or two in the right direction. Thanks. #include <stdio.h> #include <math.h> int main() {...
8
4429
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 looks like this header file
1
4572
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 do, but because I can't seem to locate something that is even close... I am posting... I would like to thank this community, I have received a great deal of help already. Background: I have a pre-existing C code, that I have written, which works....
0
9694
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9553
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10509
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10281
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9095
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4152
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2953
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.