From the XLC/C++ Programming guide (V2.3), chapter 20, "Combining C or C++ and 
Assembler programs", page 281 in the PDF, page number 245:

Use the Language Environment CEEENTRY prolog macro with MAIN=YES
specified so that z/OS Language Environment is initialized.
Once you are in the assembler program, you can call other C or C++ programs
from the assembler.

Peter

-----Original Message-----
From: IBM Mainframe Assembler List <[email protected]> On Behalf 
Of Rick Troth
Sent: Tuesday, June 6, 2023 11:56 AM
To: [email protected]
Subject: Re: Calling C functions from HLASM

Forgive me if you already know ...

C requires a stack (at least), sometimes more for sake of minimizing the 
surprise factor (for developers who think it's always a Unix thing).
After that, there's not much difference (in my experience) to call a C 
routine than to call an assembler routine.
There's nothing in the code you got from ChatGPT which would instantiate 
the expected stack and supplemental environment.

Have you called COBOL from assembler? Similar game there, and similar 
instantiation req (LE and whatever it has evolved into these days).

I hope this helps.

-- R; <><



On 6/6/23 11:27, Dave Clark wrote:
>          Would someone show me an example of calling a C function from
> HLASM?  I tried asking ChatGPT and got the following.  I don't see how
> this will link from HLASM to the C function.
>
>           PRINT NOGEN
>           TITLE 'HLASM Calling ldap_open'
>
>           USING *,12
>           LR 12,15
>           LA 15,SAVEAREA
>
>           ENTRY START
>
> SAVEAREA DS 18F
>
> LDAP_OPEN EQU *
>           DROP 0
>           LR 15,13
>           BALR 14,15
>           USING LDAP_OPEN,14
>           DROP 1
>           L 1,LDAP_HOSTNAME
>           L 2,LDAP_PORT
>           L 3,LDAP_RESULT
>           BALR 14,15
>           USING LDAP_OPEN,14
>           DROP 0
>           L 15,SAVEAREA
>           RETURN (14,12),RC=0
>
> START    DS 0H
>           ...
>           ... ; HLASM code
>           ...
>           LA 1,LDAP_HOSTNAME
>           LA 2,LDAP_PORT
>           LA 3,LDAP_RESULT
>           BALR 14,15
>           USING LDAP_OPEN,14
>           ...
>           ... ; Continue with HLASM code
>           ...
>           PRINT NOGEN
>           END START
>
> Sincerely,
>
> Dave Clark

This message and any attachments are intended only for the use of the addressee 
and may contain information that is privileged and confidential. If the reader 
of the message is not the intended recipient or an authorized representative of 
the intended recipient, you are hereby notified that any dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please notify us immediately by e-mail and delete the message and any 
attachments from your system.

Reply via email to