Article ID: 104512
Article Last Modified on 8/16/2005
BC /O Basicmodulename;
BC Basicmodulename
CL /c /AM Cmodulename
NOTE: For convenience, the medium memory model is used for the C programs. If the large memory model were used instead (/AL instead of /AM), all pointers would have to be explicitly defined as near.
LINK /NOE Basicmodulename Cmodulename;
DECLARE SUB NumericNear CDECL (a%,b&,c!,d#) a% = 32767 b& = 32769 c! = 123.312 d# = 129381.333# CLS CALL NumericNear(a%, b&, c!, d#) LOCATE 5, 1 END
#include <stdio.h>
void NumericNear(int *a, long *b, float *c, double *d) {
printf("INTEGER %d\n", *a);
printf("LONG %ld\n", *b);
printf("FLOAT %f\n", *c);
printf("DOUBLE %lf\n", *d);
}
DECLARE SUB NumericFar CDECL (_
BYVAL p1o AS INTEGER, BYVAL p1s AS INTEGER,_
BYVAL p2o AS INTEGER, BYVAL p2s AS INTEGER,_
BYVAL p3o AS INTEGER, BYVAL p3s AS INTEGER,_
BYVAL p4o AS INTEGER, BYVAL p4s AS INTEGER)
a% = 32767
b& = 32769
c! = 123.312
d# = 129381.333#
CLS
CALL NumericFar(VARPTR(a%), VARSEG(a%),_
VARPTR(b&), VARSEG(b&),_
VARPTR(c!), VARSEG(c!),_
VARPTR(d#), VARSEG(d#))
LOCATE 5, 1
END
#include <stdio.h>
void NumericFar(int far *a, long far *b, float far *c, double far *d)
{
printf("INTEGER %d\n", *a);
printf("LONG %ld\n", *b);
printf("FLOAT %f\n", *c);
printf("DOUBLE %lf\n", *d);
}
DECLARE SUB NumericValue CDECL (_
BYVAL p1 AS INTEGER,_
BYVAL p2 AS LONG,_
BYVAL p3 AS SINGLE,_
BYVAL p4 AS DOUBLE)
a% = 32767
b& = 32769
c! = 123.312
d# = 129381.333#
CLS
CALL NumericValue(a%, b&, c!, d#)
LOCATE 5, 1
END
#include <stdio.h>
void NumericValue(int a, long b, float c, double d) {
printf("INTEGER %d\n", a);
printf("LONG %ld\n", b);
printf("FLOAT %f\n", c);
printf("DOUBLE %lf\n", d);
}
DECLARE SUB test CDECL (BYVAL a%, BYVAL b%)
CALL test(ASC("A"), ASC("B"))
END
#include <stdio.h>
void test(char a, char b)
{
printf("%c %c\n",a,b);
}
DECLARE SUB StringFar CDECL (BYVAL addr AS LONG, ln AS INTEGER) CLS a$ = "This is a test" + CHR$(0) CALL StringFar(SSEGADD(a$), LEN(a$)) LOCATE 20, 1 END
#include <stdio.h>
void StringFar(char far *a, int *len) {
int i;
printf("The string is : %Fs\n\n", a);
printf(" Index Value Character\n");
for (i=0;i < *len; i++) {
printf(" %2d %3d %c\n", i, a[i], a[i]);
}
}
| Index | Value | Character |
|---|---|---|
| 0 | 84 | T |
| 1 | 104 | h |
| 2 | 105 | i |
| 3 | 115 | s |
| 4 | 32 | |
| 5 | 105 | i |
| 6 | 115 | s |
| 7 | 32 | |
| 8 | 97 | a |
| 9 | 32 | |
| 10 | 116 | t |
| 11 | 101 | e |
| 12 | 115 | s |
| 13 | 116 | t |
| 14 | 0 |
DECLARE SUB StringNear CDECL (_
BYVAL p1o AS INTEGER,_
p3 AS INTEGER)
DIM a AS STRING * 15
CLS
a = "This is a test" + CHR$(0)
CALL StringNear(VARPTR(a), LEN(a))
LOCATE 20, 1
END
#include <stdio.h>
void StringNear(char *a, int *len) {
int i;
printf("The string is : %s \n\n",a);
printf(" Index Value Character\n");
for (i=0;i < *len; i++) {
printf(" %2d %3d %c\n", i, a[i], a[i]);
}
}
| Index | Value | Character |
|---|---|---|
| 0 | 84 | T |
| 1 | 104 | h |
| 2 | 105 | i |
| 3 | 115 | s |
| 4 | 32 | |
| 5 | 105 | i |
| 6 | 115 | s |
| 7 | 32 | |
| 8 | 97 | a |
| 9 | 32 | |
| 10 | 116 | t |
| 11 | 101 | e |
| 12 | 115 | s |
| 13 | 116 | t |
| 14 | 0 |
DECLARE SUB StringFar CDECL (_
BYVAL p1o AS INTEGER,_
BYVAL p1s AS INTEGER,_
p3 AS INTEGER)
DIM a AS STRING * 15
CLS
a = "This is a test" + CHR$(0)
CALL StringFar(VARPTR(a), VARSEG(a), LEN(a))
END
#include <stdio.h>
void StringFar(char far *a, int *len) {
int i;
printf("The string is : %Fs\n\n", a);
printf(" Index Value Character\n");
for (i=0;i < *len; i++) {
printf(" %2d %3d %c\n", i, a[i], a[i]);
}
}
| Index | Value | Character |
|---|---|---|
| 0 | 84 | T |
| 1 | 104 | h |
| 2 | 105 | i |
| 3 | 115 | s |
| 4 | 32 | |
| 5 | 105 | i |
| 6 | 115 | s |
| 7 | 32 | |
| 8 | 97 | a |
| 9 | 32 | |
| 10 | 116 | t |
| 11 | 101 | e |
| 12 | 115 | s |
| 13 | 116 | t |
| 14 | 0 |
DECLARE SUB CSUB CDECL() TYPE fixstringtype B AS STRING * 26 END TYPE CALL CSUB END SUB BASSUB(B AS fixstringtype) PRINT B.B PRINT LEN(B.B) END SUB
#include <string.h>
extern void pascal bassub(char *basfixstring);
char thestring[26];
void csub() {
strcpy(thestring, "This is the string");
bassub(thestring);
}
TYPE record a AS INTEGER b AS STRING * 20 c AS SINGLE END TYPE DECLARE SUB TypeReference CDECL (p1 AS record) CLS DIM element AS record element.a = 128 element.b = DATE$ + CHR$(0) element.c = 39.6 CALL TypeReference(element) LOCATE 4, 1 END
#include <stdio.h>
struct record {
int a;
char b[20];
float c;
};
void TypeReference(struct record *element) {
printf("Record.A = %d\n", element->a);
printf("Record.B = %s\n", element->b);
printf("Record.C = %f\n", element->c);
}
TYPE record a AS INTEGER b AS STRING * 20 c AS SINGLE END TYPE DECLARE SUB TypeReference CDECL (BYVAL p1o AS INTEGER, _ BYVAL p1s AS INTEGER) CLS DIM element AS record element.a = 128 element.b = DATE$ + CHR$(0) element.c = 39.6 CALL TypeReference(VARPTR(element), VARSEG(element)) LOCATE 4, 1 END
#include <stdio.h>
struct record {
int a;
char b[20];
float c;
};
void TypeReference(struct record far *element) {
printf("Record.A = %d\n", element->a);
printf("Record.B = %s\n", element->b);
printf("Record.C = %f\n", element->c);
}
DECLARE SUB IntArray CDECL (BYVAL p1 AS INTEGER, BYVAL p2 AS INTEGER) DEFINT A-Z DIM i AS INTEGER DIM array(10) AS INTEGER CLS FOR i = 1 TO 10 array(i) = i NEXT i 'Array must be a FAR pointer, so offset and segment must be passed: CALL IntArray(VARPTR(array(0)), VARSEG(array(0))) LOCATE 13, 1 PRINT "Back in Basic" FOR i = 1 TO 10 PRINT i, array(i) NEXT i END
#include <stdio.h>
void IntArray (int far *array) {
int i;
printf("Index Value\n");
for (i = 0; i <= 10; i++) {
printf(" %d %d\n", i, array[i]);
array[i] = array[i] + 100;
}
}
| Index | Value |
|---|---|
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 4 | 4 |
| 5 | 5 |
| 6 | 6 |
| 7 | 7 |
| 8 | 8 |
| 9 | 9 |
| 10 | 10 |
| Back in Basic | |
| 1 | 101 |
| 2 | 102 |
| 3 | 103 |
| 4 | 104 |
| 5 | 105 |
| 6 | 106 |
| 7 | 107 |
| 8 | 108 |
| 9 | 109 |
| 10 | 110 |
DECLARE SUB LongArray CDECL (_
BYVAL p1 AS INTEGER,_
BYVAL p2 AS INTEGER)
DEFINT A-Z
DIM i AS LONG
DIM array(10) AS LONG
CLS
FOR i = 1 TO 10
array(i) = i + 100
NEXT i
'Array must be a FAR pointer, so offset and segment must be passed:
CALL LongArray(VARPTR(array(0)), VARSEG(array(0)))
LOCATE 13, 1
PRINT "Back in Basic"
FOR i = 1 TO 10
PRINT i, array(i)
NEXT i
END
#include <stdio.h>
void LongArray(long far *array) {
int i;
printf("Index Value\n");
for (i=0; i < 11; i++) {
printf(" %d %ld\n", i, array[i]);
array[i] = array[i] + 100;
}
}
| Index | Value |
|---|---|
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 4 | 4 |
| 5 | 5 |
| 6 | 6 |
| 7 | 7 |
| 8 | 8 |
| 9 | 9 |
| 10 | 10 |
| Back in Basic | |
| 1 | 101 |
| 2 | 102 |
| 3 | 103 |
| 4 | 104 |
| 5 | 105 |
| 6 | 106 |
| 7 | 107 |
| 8 | 108 |
| 9 | 109 |
| 10 | 110 |
Index Value 0 0 1 101 2 102 3 103 4 104 5 105 6 106 7 107 8 108 9 109 10 110 Back in Basic 1 201 2 202 3 203 4 204 5 205 6 206 7 207 8 208 9 209 10 210
DECLARE SUB FloatArray CDECL (BYVAL p1 AS INTEGER, BYVAL p2 AS INTEGER) DEFINT A-Z DIM i AS SINGLE DIM array(10) AS SINGLE CLS FOR i = 1 TO 10 array(i) = i + 100 NEXT i 'Array must be a FAR pointer, so offset and segment must be passed: CALL FloatArray(VARPTR(array(0)), VARSEG(array(0))) LOCATE 13, 1 PRINT "Back in Basic" FOR i = 1 TO 10 PRINT i, array(i) NEXT i END
#include <stdio.h>
void FloatArray(float far *array) {
int i;
printf("Index Value\n");
for (i=0; i < 11; i++) {
printf(" %d %f\n", i, array[i]);
array[i] = array[i]+100;
}
}
Index Value 0 0.000000 1 101.000000 2 102.000000 3 103.000000 4 104.000000 5 105.000000 6 106.000000 7 107.000000 8 108.000000 9 109.000000 10 110.000000 Back in Basic 1 201 2 202 3 203 4 204 5 205 6 206 7 207 8 208 9 209 10 210
DECLARE SUB DoubleArray CDECL (BYVAL p1 AS INTEGER, BYVAL p2 AS INTEGER) DEFINT A-Z DIM i AS DOUBLE DIM array(10) AS DOUBLE CLS FOR i = 1 TO 10 array(i) = i + 100 NEXT i 'Array must be a FAR pointer, so offset and segment must be passed: CALL DoubleArray(VARPTR(array(0)), VARSEG(array(0))) LOCATE 13, 1 PRINT "Back in Basic" FOR i = 1 TO 10 PRINT i, array(i) NEXT i END
#include <stdio.h>
void DoubleArray(double far *array) {
int i;
printf("Index Value\n");
for (i=0; i < 11; i++) {
printf(" %d %lf\n", i, array[i]);
array[i] = array[i] + 100;
}
}
Index Value 0 0.000000 1 101.000000 2 102.000000 3 103.000000 4 104.000000 5 105.000000 6 106.000000 7 107.000000 8 108.000000 9 109.000000 10 110.000000 Back in Basic 1 201 2 202 3 203 4 204 5 205 6 206 7 207 8 208 9 209 10 210
DECLARE SUB StringFar CDECL (length%, num%, BYVAL p3o AS INTEGER,_ BYVAL p3s AS INTEGER) DIM array(10) AS STRING * 10 CLS length% = 10 num% = 3 FOR i = 0 TO 10 array(i) = STRING$(9, 65 + i) + CHR$(0) NEXT i CALL StringFar(length%, num%, VARPTR(array(0)), VARSEG(array(0))) END
#include <stdio.h>
void StringFar(int *len, int *num, char far *array) {
int i;
printf("The string length is : %d \n\n",*len);
printf("The number of elements is : %d \n\n",*num);
printf(" Index String\n");
for (i=0; i < *num; i++) {
printf(" %2d %Fs\n", i, array);
array=array+*len;
}
}
Index String 0 AAAAAAAAA 1 BBBBBBBBB 2 CCCCCCCCC
TYPE record a AS INTEGER b AS STRING * 20 c AS SINGLE END TYPE DECLARE SUB TypeArray CDECL (BYVAL p1o AS INTEGER, BYVAL p1s AS INTEGER) DIM element(10) AS record CLS FOR I = 0 TO 10 element(I).a = 128 + I element(I).b = STR$(I) + ". " + DATE$ + CHR$(0) element(I).c = 39.6 * I NEXT I CALL TypeArray(VARPTR(element(0)), VARSEG(element(0))) END
#include <stdio.h>
struct record {
int a;
char b[20];
float c;
};
void TypeArray(struct record far *element) {
int i;
for (i=0; i<3; i++) {
printf("Record[%d].A = %d\n", i, element->a);
printf("Record[%d].B = %Fs\n", i, element->b);
printf("Record[%d].C = %f\n", i, element->c);
printf("\n");
element++;
}
}
DECLARE SUB TwoIntArray CDECL (BYVAL p1o AS INTEGER, BYVAL p1s AS INTEGER)
FOR j = 0 TO 4
x(i, j) = i * 10 + j
NEXTNEXT CALL TwoIntArray(VARPTR(x(0, 0)), VARSEG(x(0, 0))) LOCATE 5, 1 END
#include <stdio.h>struct two_int_array {
int a[5][5];};
void TwoIntArray(struct two_int_array far *x) {
int i,j;
for (i = 0; i < 5; i++) {
for (j = 0; j < 5; j++) {
printf(" %3d ", x->a[i][j]);
}
printf("\n");
}
}
0 10 20 30 40 1 11 21 31 41 2 12 22 32 42 3 13 23 33 43 4 14 24 34 44
DECLARE SUB RCommon CDECL (BYVAL p1o AS INTEGER, BYVAL p1s AS INTEGER)
element3 AS SINGLE
#include <stdio.h>
int a; char b[20]; float c;};
void RCommon(struct common_block far *pointer) {
printf("Element1 = %d\n", pointer->a);
printf("Element2 = %Fs\n", pointer->b);
printf("Element3 = %f\n", pointer->c);
}
DECLARE SUB StringFar CDECL (BYVAL p1o AS INTEGER, BYVAL p1s AS INTEGER,_ p3 AS INTEGER)
#include <stdio.h>
void StringFar(char far *a, int *len) {
int i;
printf("The string is : %Fs\n\n",a);
printf(" Index Value Character\n");
for (i = 0;i < *len; i++) {
printf(" %2d %3d %c\n", i, a[i], a[i]);
}
/* This loop writes over the end of the string */
for (i = 10; i < *len; i++) {
a[i] = 64; // ASCII value for '@'
}
}
This is a @@@@
DECLARE FUNCTION cintfunc% CDECL () DECLARE FUNCTION clongfunc& CDECL () DECLARE FUNCTION csinglefunc! CDECL () DECLARE FUNCTION cdoublefunc# CDECL ()
int cintfunc(void) {
int theint = 32767;
return(theint);
}
long thelong = 32769; return(thelong);}
float thefloat = 123.312F; return(thefloat);}
double thedouble = 129381.123; return(thedouble);}
Additional query words: VBmsdos 1.00
Keywords: KB104512