HP3000-L Archives

December 1995, Week 1

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Bruce Toback <[log in to unmask]>
Reply To:
Bruce Toback <[log in to unmask]>
Date:
Tue, 5 Dec 1995 10:33:01 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (51 lines)
Valgeir Gudmundsson writes:
 
>I'm using HP Cobol and I want to call subroutines written in C.
>I have done this for other Cobols and it worked fine. In the manual
>for HP Cobol it is explained that one can declare subroutines called intrinsics
>in the file SYSINTR.PUB.SYS. I would like to know if this subroutines can be
>wrriten in C and if someone had an example on this method.
 
It's actually easier than that. You can call subroutines written in C and
linked in with your program (LINK FROM=<cobol-object>,<c-object>...;
TO=...). You don't need to declare them in the SYSINTR file.
 
If you use ANSI CALL (CALL literal-1 USING arg1, arg2...) all parameters
are passed as pointers. Watch out for misalignment; integer (USAGE COMP)
items that aren't level 01 or level 77 are not necessarily aligned
properly; if you use them, you'll get an INVALID DATA ADDRESS trap. Your
routines must be named entirely in lower case.
 
COBOL provides a few extensions that get around this. First, if you precede
the string in literal-1 with a backslash, the compiler preserves the case
of the identifier when it passes it to the linker. Thus, to call a routine
called RMInitialize, you'd say CALL "\RMInitialize", with the backslash
protecting the mixed-case name.
 
Second, if you surround an argument with backslashes, the compiler will
pass the argument by value. This gets around the alignment problem, of
course. For example, if your C routine is declared as
 
    int Foo(char * aString, int anInt)
 
you'd call this in HP Cobol as
 
    CALL "\Foo" USING MY-DISPLAY-FIELD  \MY-COMP-FIELD\
          GIVING ANOTHER-COMP-FIELD.
 
Again, you don't need to mess with the SYSINTR file to do this. The SYSINTR
file is used to store declarations so that COBOL (and other languages) can
understand parameter passing conventions that can't be expressed in that
language -- for example, call by value in the case of COBOL. Messing with
SYSINTR requires a Pascal compiler and is generally messy, especially since
HP regards it as a system file and replaces it on updates software updates.
 
-- Bruce
 
---------------------------------------------------------------------------
Bruce Toback    Tel: (602) 996-8601| My candle burns at both ends;
OPT, Inc.            (800) 858-4507| It will not last the night;
11801 N. Tatum Blvd. Ste. 142      | But ah, my foes, and oh, my friends -
Phoenix AZ 85028                   | It gives a lovely light.
[log in to unmask]                 |     -- Edna St. Vincent Millay

ATOM RSS1 RSS2