Microsoft KB Archive/58411

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 09:19, 21 July 2020 by X010 (talk | contribs) (Text replacement - ">" to ">")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Base


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:

  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
                


Additional query words: QuickBas BasicCom

Keywords: KB58411