C Char Parameters Passed from Basic as 2-Byte Parameters (58411)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 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:

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

    1. Compile in Basic as follows:
               BC testb ;
      								
    2. For Microsoft C Versions 5.0 and 5.1, compile as follows:
               CL -c -AL test.c ;
      								
    3. For Microsoft QuickC, compile as follows:
               QCL -c -AL test.c ;
      								
  2. LINK with the following line:
          LINK /NOE testb+test ;
    						
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("A"), ASC("B"))
   END
				


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

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB58411