Microsoft KB Archive/44137

= CALLing C to Return Single-Precision Gives Incorrect Results =

Article ID: 44137

Article Last Modified on 11/21/2006



This article was previously published under Q44137



SYMPTOMS
From within a Basic program, invoking a Microsoft C or QuickC function that attempts to return a single-precision number may give unpredictable results. Returning any other numeric type from a C function gives correct results.

To work around the problem, you can pass the single-precision number as a parameter (whose value is set inside the C function and passed back).

This information applies to Microsoft C Compiler versions 5.00, 5.10, and 6.00, and to Microsoft QuickC versions 1.00, 1.01, 2.00, 2.01, 2.50, and 2.51.



STATUS
Microsoft has confirmed this to be a bug in QuickBasic versions 4.00, 4.00b, and 4.50 for MS-DOS, in Microsoft Basic Compiler versions 6.00 and 6.00b (buglist6.00, buglist6.00b) for MS-DOS and OS/2, and in Microsoft Basic Professional Development System (PDS) versions 7.00 and 7.10 for MS-DOS and MS OS/2 (buglist7.00, buglist7.10). We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

Note that only certain versions of Basic link with certain versions of C, as explained in a separate article found by searching in this Knowledge Base for the following words:

Basic and C and QuickC and link and compatible and pass and calling



Code Example
'Basic code to show incorrect return of a single DECLARE FUNCTION doublefun# CDECL ALIAS &quot;_doublefun&quot; DECLARE FUNCTION singlefun! CDECL ALIAS &quot;_singlefun&quot; DECLARE SUB floatchange CDECL (BYVAL offset%)

x# = doublefun#                  'Works correctly y! = singlefun! 'Returns wrong value z! = 0 CALL floatchange (VARPTR(z!))    'Workaround - pass as parameter PRINT x# PRINT y! PRINT z! END

/* C code, compile with /AM (medium memory model)*/ double doublefun       /* returns a double */ { double x;  x = 1.45; printf(&quot;%f\n&quot;,x); return x; }

float singlefun        /* returns a single */ { float x;  x = 1.45; printf(&quot;%f\n&quot;,x); return x; }

void floatchange (x)    /* Takes a single as a parameter */ float *x; { *x = 1.45; printf(&quot;%f\n&quot;,x); }

Program Output
 1.450000 1.450000             <--These are the C PRINTF statements. 1.450000

1.45 2                     <--These are the Basic PRINT statements. 1.45

Additional query words: QuickBas BasicCom buglist4.00 buglist4.00b buglist4.50

Keywords: KB44137

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.