Operating System - OpenVMS
1753408 Members
7407 Online
108793 Solutions
New Discussion

Re: Access Basic COMMON,MAP, and VAR from a C program

 
SOLVED
Go to solution

Access Basic COMMON,MAP, and VAR from a C program

Hi...

I want to from my C functions access data from the BASIC main program.

I link the programs together and the main program has a MAP.

Example

MAP (TEST_MAP) STRING TEST_STR = 20

How can i access it from my C function.

4 REPLIES 4
Hein van den Heuvel
Honored Contributor
Solution

Re: Access Basic COMMON,MAP, and VAR from a C program

The key to solving this is in the

"HP C Userâ s Guide for OpenVMS Systems"
4.8.2 Program Sections Created by HP C

You start by creating the BASIC program, compile with /LIST and look for the PSECT supporting the MAP there. You can also do a test link/MAP, ingnoring missing references and looking at map for the psect

6 TEST_MAP 32 NOPIC OVR REL GBL NOSHR NOEXE RD WRT OCTA

Now pick the corresponding Storage-Class Code from "Table 4â 7 Combination Attributes"

And go back up to finds ways to declare those.

For example:

$ typ tmp.bas
COMMON (TEST_MAP) STRING TEST_STR = 20
TEST_STR = "Hello world"
CALL test_C
end

$ type test_c.c
#include stdio
#pragma extern_model common_block shr
extern struct {
char test[20];
char zero;
} TEST_MAP;
test_c() {
TEST_MAP.zero = 0;
printf ("-%s-\n", TEST_MAP.test);
return;
}

$ run tmp
-Hello world -

Note 1) You figure the details: This example still generates:
%LINK-W-MULPSC, conflicting attributes for psect TEST_MAP

Note 2) you can coerce PSECT attributes with LINK options.

Note 3) The 'zero' byte is for my example convenience. You need to know amd take into account that BASIC strings are NOT zero terminated.

Enjoy!
Hein.
Hein van den Heuvel
Honored Contributor

Re: Access Basic COMMON,MAP, and VAR from a C program

Oh, be sure to google for things like:
"pragma extern_model common_block shr"

This finds intersting example usages as well as reference to the HP C manuals:

For example:

http://www.pottsoft.com/home/c_course/course.html

Hein.

Re: Access Basic COMMON,MAP, and VAR from a C program

Thx Hein!

Re: Access Basic COMMON,MAP, and VAR from a C program

Closing the thread due to good answer