[Info-vax] Any Way to Pass Arrays of Strings from C to Basic?
Neil Rieck
n.rieck at sympatico.ca
Wed Nov 13 11:17:58 EST 2019
On Thursday, October 31, 2019 at 2:40:12 PM UTC-4, Craig Dedo wrote:
> Is there any way to pass arrays of character strings from C to Basic? For both languages I'm using the current versions of the languages:
> VSI C V7.4-002 on OpenVMS Alpha V8.4-2L2
> VSI BASIC V1.8-005 on OpenVMS V8.4-2L2
>
> I need to pass character string variables from a main program or procedure written in C to a subroutine written in Basic and get back character string data from the Basic subroutine. I had to write the subroutine in Basic because it needs to call a utility subroutine in Basic that uses arrays of varying-length character strings.
>
> This post is an expansion of my original post on October 21. This morning management decided that we will be using multiple instances of the same kind of data in one subroutine call. I.e., instead of getting all of the information for one part number at a time we will be getting the information for up to 1000 part numbers at a time.
>
> Thus, the utility routine that I'm calling from my interface routine in Basic will be returning a 2-D array of varying length character strings. I'm still going to use an interface routine written in Basic so that I can simplify the interface between C and Basic.
>
> In the original problem, using fixed-length character string descriptors worked very well for passing the string arguments from the calling routine in C to the interface routine in Basic. Now I need to write descriptors for arrays of fixed-length character strings.
>
> I tried to research this on my own but came up empty. I have read thru the text of descrip.h, the latest reference manuals and user guides for both Basic and C, and the OpenVMS Programming Concepts Manual. Nothing I have found tells me how to fill in all of the elements in the array descriptor, only some of them.
>
> Here is a greatly simplified example. On the C side:
> const size_t STRING_LENGTH = 30;
> const size_t NPARTS = 1000;
> char Part_Number_lsza[NPARTS][STRING_LENGTH+1];
> char Oldest_Invoice_Number_lsza[NPARTS][STRING_LENGTH+1];
> /*
> Make the call to the interface routine written in Basic. The variables ending in _ldsc are the array descriptors for the arrays of character strings.
> */
> Get_DIA_Return_Eligibility ( &Part_Number_ldsc, &Oldest_Invoice_Number_ldsc );
>
> On the Basic side:
> Sub ( String Part_Number_asa(), Oldest_Invoice_Number_asa() )
>
> What I need to learn how to do is to construct the array descriptors for the arrays of strings. I know how to set the fields for the data type, class code, and address but I'm not sure about many of the other fields. Here are some of my questions.
>
> * Should the length of the array element be STRING_LENGTH or STRING_LENGTH+1? I believe it should be STRING_LENGTH but I'm not sure.
>
> * What do dsc$b_scale and dsc$v_fl_binscale do? I'd prefer t use power-of-ten so dsc$v_fl_binscale should be off. Should dsc$b_scale have any value other than zero (0)? If so, wht value should it have?
>
> * I know that dsc$b_dimct should be 1 because I intend to pass 1-dimensional arrays to Basic.
>
> * I believe that dsc$l_arsize should be 31,000 since I need to include a null character at the end of each string element in the array and there are 1000 elements. Is this correct?
>
> * Do I need to include the optional dimension multiplier block? I suspect that yes, I need to include it since I have null-terminated strings in my array so the address difference between array elements is one more than the length of the array element. If so, what should the value of dsc$l_m be?
>
> BTW, this is NOT an academic assignment. It is a real production problem in a commercial environment with real profit and loss responsibility and real money at stake.
>
> Any help would be very much appreciated.
>
> Sincerely,
> Craig T. Dedo. OpenVMS Software Development Consultant
> Navistar, Inc.
> 2701 Navistar Drive
> Lisle, IL 60532
As others have already mentioned, this can be simple or hard depending upon what you are trying to do. Having said that, you will find simple and complex examples here (search: Hybrid Programming)
http://neilrieck.net/demo_vms_html/openvms_demo_index.html
Hybrid Demo-5 takes things to extremes. Here, I wrote some code to deal with a VMS-BASIC program which calls a DEC-c routine to connect to MySQL. The data strings returned from MySQL are copied into a BASIC-declared array-of-strings.
Neil Rieck
Waterloo, Ontario, Canada.
http://neilrieck.net/
More information about the Info-vax
mailing list