[Info-vax] Any Way to Pass Character String Arguments from C to Basic?
Jonathan
jtcegh at gmail.com
Tue Oct 22 14:39:30 EDT 2019
If you don't want to use descriptors in C, you can alias the argument types in BASIC.
b1 is safe, b2 and b3 open to error, but more useful/fast for some purposes.
JUC$ type/nopage c.c
#include <string.h>
void b1(char *s, short n);
void b2(char *s, short n);
void b3(char *s, short n);
int main(int argc,char *argv[])
{
char *test = "Test";
int testlen = strlen(test);
b1(test,testlen);
b2(test,testlen);
b3(test,testlen);
return 0;
}
JUC$ type/nopage b.bas
function long b1( long a by value, word n by value )
%include "$DSCDEF" %from %library "SYS$SHARE:BASIC$STARLET"
external long function b1a( DSCDEF1 )
declare DSCDEF1 dsc
dsc::DSC$A_POINTER = a
dsc::DSC$W_MAXSTRLEN = n
dsc::DSC$B_DTYPE = DSC$K_DTYPE_T
dsc::DSC$B_CLASS = DSC$K_CLASS_S
end function b1a( dsc )
function long b1a( string s )
print "s=";s
end function
function long b2( string x = 32767 by ref, word n by value )
external long function b1a( string )
end function b1a( left$( x, n ) )
function long b3( byte b(32766) by ref, word n by value )
print "s=";
for i = 0 to n - 1
print chr$(b(i));
next i
print
end function
JUC$ cc c
JUC$ basic b
JUC$ link c+b
JUC$ run c
s=Test
s=Test
s=Test
More information about the Info-vax
mailing list