<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Incorrect float value returned from C function? in Operating System - OpenVMS</title>
    <link>https://community.hpe.com/t5/operating-system-openvms/incorrect-float-value-returned-from-c-function/m-p/5091793#M39296</link>
    <description>Greetings,&lt;BR /&gt;&lt;BR /&gt;I am attempting to write a unit test harness to test internal functions in a stand-alone c program.  &lt;BR /&gt;&lt;BR /&gt;Following are two pieces of simplified code to demonstrate my situation.  First, the main program:&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;#include &lt;FLOAT.H&gt;&lt;BR /&gt;extern float GetRatioMax()&lt;BR /&gt;{&lt;BR /&gt;    float fResult;&lt;BR /&gt;&lt;BR /&gt;    fResult = 4.25;&lt;BR /&gt;    printf("\nfloat value inside function: %f", fResult);&lt;BR /&gt;    return(fResult);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;/*  Need the following #ifdef to link cleanly against the unit test harness.  */&lt;BR /&gt;#ifdef UNIT_TEST_ON&lt;BR /&gt;test_uth()&lt;BR /&gt;#else&lt;BR /&gt;main()&lt;BR /&gt;#endif&lt;BR /&gt;{&lt;BR /&gt;/*  Main left blank for simplicity.  */&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Now, the unit test harness:&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;#include &lt;FLOAT.H&gt;&lt;BR /&gt;main()&lt;BR /&gt;{&lt;BR /&gt;    float fRatio;&lt;BR /&gt;    fRatio = GetRatioMax();&lt;BR /&gt;    printf("\nValue after return: %f", fRatio);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Here are the results I get when I run the program on my system:&lt;BR /&gt;float value inside function: 4.250000&lt;BR /&gt;Value after return: 38.000000&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&lt;BR /&gt;Kevin Iliff&lt;/FLOAT.H&gt;&lt;/STDLIB.H&gt;&lt;/STDIO.H&gt;&lt;/FLOAT.H&gt;&lt;/STDLIB.H&gt;&lt;/STDIO.H&gt;</description>
    <pubDate>Fri, 08 Feb 2008 14:45:40 GMT</pubDate>
    <dc:creator>Kevin Iliff</dc:creator>
    <dc:date>2008-02-08T14:45:40Z</dc:date>
    <item>
      <title>Incorrect float value returned from C function?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/incorrect-float-value-returned-from-c-function/m-p/5091793#M39296</link>
      <description>Greetings,&lt;BR /&gt;&lt;BR /&gt;I am attempting to write a unit test harness to test internal functions in a stand-alone c program.  &lt;BR /&gt;&lt;BR /&gt;Following are two pieces of simplified code to demonstrate my situation.  First, the main program:&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;#include &lt;FLOAT.H&gt;&lt;BR /&gt;extern float GetRatioMax()&lt;BR /&gt;{&lt;BR /&gt;    float fResult;&lt;BR /&gt;&lt;BR /&gt;    fResult = 4.25;&lt;BR /&gt;    printf("\nfloat value inside function: %f", fResult);&lt;BR /&gt;    return(fResult);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;/*  Need the following #ifdef to link cleanly against the unit test harness.  */&lt;BR /&gt;#ifdef UNIT_TEST_ON&lt;BR /&gt;test_uth()&lt;BR /&gt;#else&lt;BR /&gt;main()&lt;BR /&gt;#endif&lt;BR /&gt;{&lt;BR /&gt;/*  Main left blank for simplicity.  */&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Now, the unit test harness:&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;#include &lt;FLOAT.H&gt;&lt;BR /&gt;main()&lt;BR /&gt;{&lt;BR /&gt;    float fRatio;&lt;BR /&gt;    fRatio = GetRatioMax();&lt;BR /&gt;    printf("\nValue after return: %f", fRatio);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Here are the results I get when I run the program on my system:&lt;BR /&gt;float value inside function: 4.250000&lt;BR /&gt;Value after return: 38.000000&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&lt;BR /&gt;Kevin Iliff&lt;/FLOAT.H&gt;&lt;/STDLIB.H&gt;&lt;/STDIO.H&gt;&lt;/FLOAT.H&gt;&lt;/STDLIB.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Fri, 08 Feb 2008 14:45:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/incorrect-float-value-returned-from-c-function/m-p/5091793#M39296</guid>
      <dc:creator>Kevin Iliff</dc:creator>
      <dc:date>2008-02-08T14:45:40Z</dc:date>
    </item>
    <item>
      <title>Re: Incorrect float value returned from C function?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/incorrect-float-value-returned-from-c-function/m-p/5091794#M39297</link>
      <description>Kevin,&lt;BR /&gt;&lt;BR /&gt;Welcome to the OpenVMS itrc forum!&lt;BR /&gt;&lt;BR /&gt;When compiling the 'main' as independent module, how does the compiler know GetRatioMax() is returning a float?&lt;BR /&gt;&lt;BR /&gt;What are you not telling us, or what did I miss in your description.&lt;BR /&gt;Do you not get a warning like:&lt;BR /&gt;&lt;BR /&gt;%CC-I-IMPLICITFUNC, In this statement, the identifier "GetRatioMax" is implicitly&lt;BR /&gt;declared as a function.&lt;BR /&gt;&lt;BR /&gt;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. &lt;BR /&gt;&lt;BR /&gt;It would seem to me you need to define a function prototype somewhere down the line when compiling seperately.&lt;BR /&gt;&lt;BR /&gt;When in doubt... compile with /LIST/MACHINE and compare the instructions for the working case vs the case where you lied to the compiler.&lt;BR /&gt; &lt;BR /&gt;Hope this helps some!&lt;BR /&gt;Hein.</description>
      <pubDate>Fri, 08 Feb 2008 15:00:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/incorrect-float-value-returned-from-c-function/m-p/5091794#M39297</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2008-02-08T15:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: Incorrect float value returned from C function?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/incorrect-float-value-returned-from-c-function/m-p/5091795#M39298</link>
      <description>This compiler complaint didn't speak to you?&lt;BR /&gt;&lt;BR /&gt;alp $ cc c2&lt;BR /&gt;&lt;BR /&gt;fRatio = GetRatioMax();&lt;BR /&gt;.........^&lt;BR /&gt;%CC-I-IMPLICITFUNC, In this statement, the identifier "GetRatioMax" is implicitl&lt;BR /&gt;y declared as a function.&lt;BR /&gt;at line number 7 in file ALP$DKA0:[SMS]C2.C;1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Try declaring GetRatioMax() in the unit test&lt;BR /&gt;harness:&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;#include &lt;FLOAT.H&gt;&lt;BR /&gt;&lt;BR /&gt;float GetRatioMax( void);&lt;BR /&gt;&lt;BR /&gt;main()&lt;BR /&gt;{&lt;BR /&gt;float fRatio;&lt;BR /&gt;fRatio = GetRatioMax();&lt;BR /&gt;printf("\nValue after return: %f", fRatio);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Implicitly declared things are "int", not&lt;BR /&gt;"float".&lt;/FLOAT.H&gt;&lt;/STDLIB.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Fri, 08 Feb 2008 15:00:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/incorrect-float-value-returned-from-c-function/m-p/5091795#M39298</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2008-02-08T15:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: Incorrect float value returned from C function?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/incorrect-float-value-returned-from-c-function/m-p/5091796#M39299</link>
      <description>15:00:05, 15:00:58.  That does it.  I'm&lt;BR /&gt;through proofreading these things.</description>
      <pubDate>Fri, 08 Feb 2008 15:11:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/incorrect-float-value-returned-from-c-function/m-p/5091796#M39299</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2008-02-08T15:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Incorrect float value returned from C function?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/incorrect-float-value-returned-from-c-function/m-p/5091797#M39300</link>
      <description>Of course.  Adding the function prototype solved the problem.  Thank you for your prompt assistance.&lt;BR /&gt;&lt;BR /&gt;Kevin</description>
      <pubDate>Fri, 08 Feb 2008 15:19:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/incorrect-float-value-returned-from-c-function/m-p/5091797#M39300</guid>
      <dc:creator>Kevin Iliff</dc:creator>
      <dc:date>2008-02-08T15:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: Incorrect float value returned from C function?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/incorrect-float-value-returned-from-c-function/m-p/5091798#M39301</link>
      <description>As stated above, I added a function prototype to a header file that is included in both files, and the problem was solved.&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;Once again, thanks for your help.&lt;BR /&gt;&lt;BR /&gt;Kevin</description>
      <pubDate>Fri, 08 Feb 2008 15:36:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/incorrect-float-value-returned-from-c-function/m-p/5091798#M39301</guid>
      <dc:creator>Kevin Iliff</dc:creator>
      <dc:date>2008-02-08T15:36:25Z</dc:date>
    </item>
    <item>
      <title>Re: Incorrect float value returned from C function?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/incorrect-float-value-returned-from-c-function/m-p/5091799#M39302</link>
      <description>&amp;gt; [...] the global cc symbol on our system&lt;BR /&gt;&amp;gt; suppresses this and many other warnings.&lt;BR /&gt;&lt;BR /&gt;I trust that the wisdom of that arrangement&lt;BR /&gt;has been made abundantly clear.</description>
      <pubDate>Sat, 09 Feb 2008 16:00:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/incorrect-float-value-returned-from-c-function/m-p/5091799#M39302</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2008-02-09T16:00:31Z</dc:date>
    </item>
  </channel>
</rss>

