Microsoft KB Archive/46030

= BUG: QuickBasic Can't Print Lightspeed C's SANE Floating-Point =

Article ID: 46030

Article Last Modified on 11/21/2006



This article was previously published under Q46030



SYMPTOMS
QuickBasic's NumToASCII and PrintNumber routines for support of pure code (MBPC) libraries cannot use Think's LightspeedC floating-point numbers.

Microsoft has confirmed this limitation in Microsoft QuickBasic Version 1.00 for the Macintosh system. Microsoft is researching this problem and will post new information as it becomes available.



MORE INFORMATION
There are two reasons for this incompatibility. First, QuickBasic 1.00 uses the IEEE floating-point format. LightspeedC uses SANE (Standard Apple Numeric Environment), a common floating-point format for Macintosh languages. Second, because a pure code resource must be totally self contained, the C startup code cannot be included and, therefore, is not executed when these routines are CALLed. Part of the function of the C startup code is to initialize floating-point literals.

The support library provided for inter-language calling from QuickBasic is called BasicLib.Lib. Two routines in this library, NumToASCII and PrintNumber, correctly use C's integer and long integer types but cannot correctly convert either the float or the double.

NumToASCII and PrintNumber are documented on Pages 465 and 466 of &quot;Microsoft QuickBasic for Macintosh : Language Reference.&quot;

The following code example uses Think's LightspeedC (sold by Symantec Corporation) to create a &quot;Code Resource&quot; that demonstrates the problem. In LightspeedC, the Code Resource should be named &quot;PrintTheNumber&quot; and the library should be named &quot;PrintTheNumber&quot; as well.

Code Example
/******* PrintNum.c


 * 1) include 
 * 2) define LONG_TYPE  6
 * 3) define DOUBLE_TYPE 5
 * 4) define SNGLE_TYPE 4
 * 5) define INT_TYPE   3

PUBLIC VOID main { /* dimension the variables */ /* Variant records and their pointers. */  NUMREC thelongptr,thesingleptr,thedoubleptr;

/* Local work varialbes. */  StringPtr thestring; short int_var; long long_var; float single_var; double double_var;

SAVEREGS;

/* Initialize the pointers. */   theintptr = &theint; thelongptr = &thelong; thesingleptr = &thesingle; thedoubleptr = &thedouble;

/* Assign them some values */

int_var = 32700; theint.Int= int_var;

long_var = 500000; thelong.Long = long_var;

single_var = (float)12.3456789; thesingle.Sngle = single_var;

double_var = (double)12.3456789; thedouble.Doble = double_var;

/*******************************************************/ /* Print the numbers using NumToASCII and PrintCString */ /*******************************************************/

NumToASCII(INT_TYPE,(NUMRECPTR)theintptr,&thestring); OutNewLine;

NumToASCII(LONG_TYPE,(NUMRECPTR)thelongptr,&thestring); OutNewLine;

NumToASCII(SNGLE_TYPE,(NUMRECPTR)thesingleptr,&thestring); OutNewLine;

NumToASCII(DOUBLE_TYPE,(NUMRECPTR)thedoubleptr,&thestring); OutNewLine;

/**************************************************/ /* Print them out using the PrintNumber function. */ /**************************************************/

PrintNumber(INT_TYPE,theintptr); OutNewLine;

PrintNumber(LONG_TYPE,thelongptr); OutNewLine;

PrintNumber(SNGLE_TYPE,thesingleptr); OutNewLine;

PrintNumber(DOUBLE_TYPE,thedoubleptr); OutNewLine;

RESTREGS; } /*********************** END C PROGRAM *************/

'********************************************** '*               MBPC test                   * '* Basic program to call MBPC routine above. * '* This program calls the C pure code library * '* routine to test the PrintNumber and       * '* NumToASCII functions contained in the     * '* BasicLib.Lib library. * '********************************************** LIBRARY &quot;PrintTheNumber&quot; IF SYSTEM(4) THEN CALL LIBINIT CALL PrintTheNumber END

Additional query words: MQuickB

Keywords: kbbug KB46030

-

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

© Microsoft Corporation. All rights reserved.