Microsoft KB Archive/58411

= C Char Parameters Passed from Basic as 2-Byte Parameters =

Article ID: 58411

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Professional Development System 7.0

-



This article was previously published under Q58411



SUMMARY
Microsoft C uses 2 bytes when passing single-byte parameters; therefore, to pass a single-byte data item by value between C and Basic, the Basic parameter must be DECLAREd as an INTEGER.

This information applies to Microsoft QuickBasic Versions 4.0, 4.0b, and 4.5 for MS-DOS, to Microsoft Basic Compiler Versions 6.0 and 6.0b for MS-DOS and MS OS/2, to Microsoft Basic Professional Development System (PDS) Version 7.0 for MS-DOS and MS OS/2, to Microsoft QuickC Versions 2.0 and 2.01 for MS-DOS, and to Microsoft C Compiler Versions 5.0 and 5.1 for MS-DOS and MS OS/2.



MORE INFORMATION
The two programs below demonstrate passing a character by value from Basic to C.

To run the programs, do the following:

 Compile as follows, depending on which language you are using:

  Compile in Basic as follows: BC testb ;   For Microsoft C Versions 5.0 and 5.1, compile as follows: CL -c -AL test.c ;   For Microsoft QuickC, compile as follows: QCL -c -AL test.c ;    LINK with the following line: LINK /NOE testb+test ; </ol>

The following program, TESTB.BAS, illustrates passing characters from Basic to C by using the ASCII values and DECLAREing the C char parameter with BYVAL var AS INTEGER: DECLARE SUB test CDECL (BYVAL a%, BYVAL b%) CALL test(ASC(&quot;A&quot;), ASC(&quot;B&quot;)) END

TEST.C is as follows: #include <stdio.h>  void test(char a, char b)     { printf(&quot;%c %c\n&quot;,a,b); } When compiled and run, TESTB.EXE displays the following: <pre class="fixed_text">  A B

Additional query words: QuickBas BasicCom

Keywords: KB58411

-

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

© Microsoft Corporation. All rights reserved.