OpenVMS Source Code Demos
basic_calling_c_demo1
1000 !=================================================================================================
! title : basic_calling_c_demo1.bas
! author : Neil Rieck (https://neilrieck.net) (mailto:n.rieck@bell.net)
! what : passing data from BASIC to C (and back again)
! build : bas basic_calling_c_demo1
! : cc basic_calling_c_demo1_part2
! : link basic_calling_c_demo1, -
! basic_calling_c_demo1_part2
! history:
! ver who when what
! --- --- ------ ---------------------------------------------------------------------------------
! 100 NSR 141107 original effort
!=================================================================================================
option type=explicit !
!
external long function basic_calling_c_demo_c1(string by desc,long by ref,word by ref,byte by ref)
external sub basic_calling_c_demo_c2(string by desc,long by ref,word by ref,byte by ref)
external sub basic_calling_c_demo_c3(string by desc)
external sub basic_calling_c_demo_c4(string by desc)
!
! The next bit of crud was done to show that data can be passed
! between BASIC + C using global variables is possible (ugh!!)
!
common (abc) byte gCmn_sanity , &
long gCmnL , &
word gCmnW , &
byte gCmnB , &
word gCmnStrLen , &
string gCmnFixed$ = 30 , ! a fixed length string &
byte gCmn_last
!
! global variables (BASIC only)
!
declare string gMain$ ,&
long gMainL ,&
word gMainW ,&
byte gMainB ,&
long rc ,&
string junk$
!=======================================================
! main
!=======================================================
main:
gCmn_last = 0 ! init
gCmn_sanity = loc(gCmn_last)-loc(gCmn_sanity)+1 ! save the total byte-count
print "-i-sanity:",gCmn_sanity !
gMain$ = "hello" ! init global variables
gMainL = 1 !
gMainW = 2 !
gMainB = 3 !
gCmnL = 4 !
gCmnW = 5 !
gCmnB = 6 !
junk$ = "fixed length string data" !
gCmnFixed$ = junk$ !
gCmnStrLen = len(junk$) !
!
print "-i-calling function c1" !
rc = basic_calling_c_demo_c1(gMain$,gMainL,gMainW,gMainB)
print "-i-rc:",rc !
print "-i-gCmnL = ",gCmnL !
print "-i-gCmnW = ",gCmnW !
print "-i-gCmnB = ",gCmnB !
!
print "-i-calling void function c2" !
gMain$ = gMain$ + " there" !
gMainL = gMainL + 1 !
gMainW = gMainW + 1 !
gMainB = gMainB + 1 !
call basic_calling_c_demo_c2(gMain$,gMainL,gMainW,gMainB)
print "-i-gCmnL = ",gCmnL !
print "-i-gCmnW = ",gCmnW !
print "-i-gCmnB = ",gCmnB !
!
print "-i-calling void function c3" !
call basic_calling_c_demo_c3(gMain$) !
!
print "-i-calling void function c4" !
call basic_calling_c_demo_c4(gMain$) !
!
print "-i-exiting" !
end !
Back to
Home
Neil Rieck
Waterloo, Ontario, Canada.