- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - OpenVMS
- >
- Re: Incorrect float value returned from C function...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-08-2008 06:45 AM
тАО02-08-2008 06:45 AM
Incorrect float value returned from C function?
I am attempting to write a unit test harness to test internal functions in a stand-alone c program.
Following are two pieces of simplified code to demonstrate my situation. First, the main program:
#include
#include
#include
extern float GetRatioMax()
{
float fResult;
fResult = 4.25;
printf("\nfloat value inside function: %f", fResult);
return(fResult);
}
/* Need the following #ifdef to link cleanly against the unit test harness. */
#ifdef UNIT_TEST_ON
test_uth()
#else
main()
#endif
{
/* Main left blank for simplicity. */
}
Now, the unit test harness:
#include
#include
#include
main()
{
float fRatio;
fRatio = GetRatioMax();
printf("\nValue after return: %f", fRatio);
}
Here are the results I get when I run the program on my system:
float value inside function: 4.250000
Value after return: 38.000000
I see the value I expect inside the function, but once the program returns, the value is incorrect. If I keep things in 1 module, it works correctly. If I pass the float as an argument, it works correctly. Anybody know why this is happening? We are running OpenVMS 7.3-2.
Thanks,
Kevin Iliff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-08-2008 07:00 AM
тАО02-08-2008 07:00 AM
Re: Incorrect float value returned from C function?
Welcome to the OpenVMS itrc forum!
When compiling the 'main' as independent module, how does the compiler know GetRatioMax() is returning a float?
What are you not telling us, or what did I miss in your description.
Do you not get a warning like:
%CC-I-IMPLICITFUNC, In this statement, the identifier "GetRatioMax" is implicitly
declared as a function.
True, it's just a bunch of bits, so you coudl argue, but the compile uses floating point instructions which can re-interpret those bits. It will mov R0 (return) into the (stack) variable and then load that into a floating point register. It should do a floating point move (FMOV) from F0 to a selected target register, and optimize away the stack variable.
It would seem to me you need to define a function prototype somewhere down the line when compiling seperately.
When in doubt... compile with /LIST/MACHINE and compare the instructions for the working case vs the case where you lied to the compiler.
Hope this helps some!
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-08-2008 07:00 AM
тАО02-08-2008 07:00 AM
Re: Incorrect float value returned from C function?
alp $ cc c2
fRatio = GetRatioMax();
.........^
%CC-I-IMPLICITFUNC, In this statement, the identifier "GetRatioMax" is implicitl
y declared as a function.
at line number 7 in file ALP$DKA0:[SMS]C2.C;1
Try declaring GetRatioMax() in the unit test
harness:
#include
#include
#include
float GetRatioMax( void);
main()
{
float fRatio;
fRatio = GetRatioMax();
printf("\nValue after return: %f", fRatio);
}
Implicitly declared things are "int", not
"float".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-08-2008 07:11 AM
тАО02-08-2008 07:11 AM
Re: Incorrect float value returned from C function?
through proofreading these things.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-08-2008 07:19 AM
тАО02-08-2008 07:19 AM
Re: Incorrect float value returned from C function?
Kevin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-08-2008 07:36 AM
тАО02-08-2008 07:36 AM
Re: Incorrect float value returned from C function?
I was not getting compiler warnings because the global cc symbol on our system suppresses this and many other warnings. Time for me to enable the warnings so I can see these things.
Once again, thanks for your help.
Kevin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-09-2008 08:00 AM
тАО02-09-2008 08:00 AM
Re: Incorrect float value returned from C function?
> suppresses this and many other warnings.
I trust that the wisdom of that arrangement
has been made abundantly clear.