MIX - mixing C code with code in other languages.

This explain file describes how to link a multi-segment program written partly in C and partly in another language. There are two cases: using the standard C entry routine, and using a different entry.

Standard C Entry:

The standard C entry routine is called C$ENTRY. It performs various set-up operations, particularly setting up the C library, then invokes a routine named "main" to start executing the actual program.

With this type of program, the input to LKED should include the following:

Create_Reference -Symref C$PROGRAM  &
                 -Symref EASEE$ENTRIES
Create_Heaps -Data 64K

The Create_Run_Unit instruction should include the option

-Entry C$ENTRY

in addition to any other options desired.

The "mainline" of the program does not have to be written in C; it can be written in PL6 or Cobol as well. However, the mainline must be named "main" (in lower case). Therefore, Cobol and PL6 programmers should ensure that the mainline is named "main". This may require a linker directive to assign the name "main" to the mainline.

Cobol mainlines should be compiled with the SUB option on the $CBL85 card to avoid generating unneeded ENTDEF code. PL6 mainlines should avoid the MAIN keyword on the PROC statement, so that a SYMDEF is generated instead of an ENTDEF.

The Library directive for LKED should include the option

-System

The Library directive should specify user libraries first, then

-Language C

then any other standard language libraries needed.

The LKED input should also contain an Include instruction for the program, and whatever other instructions are desired.

Before the program terminates, it must explicitly flush any output generated by other language routines. The reason is that the C wrap-up routines can only flush C output (since every language flushes output somewhat differently).

Not Using C$ENTRY:

If you do not use the C$ENTRY as your entry point, the input to LKED should include the following:

Create_Reference -Symref EASEE$ENTRIES
Create_Heaps -Data 64K

There should not be a Create_Reference for C$PROGRAM. Also, the -Entry option of Create_Run_Unit should refer to whatever entry point is appropriate for the mainline language.

The Library directive should specify user libraries first, then

-Language C

then any other standard language libraries needed.

The LKED input should also contain an Include instruction for the program, and whatever other instructions are desired.

The mainline of the program should call the function LIB$SETUP (with no arguments) before invoking any C routines. LIB$SETUP performs various initializations required by the C library. For example, it installs a Domain Exception Processor.

Notes:

We recommend that programs should go through C$ENTRY whenever possible. C$ENTRY calls LIB$SETUP to set up the C library at the optimal point during execution.

Note that C only runs in binary floating point mode; it does NOT run in hex mode. You may find yourself in trouble even if you avoid floating point numbers in your C code (or in your other language code), because library functions may use floating point values without your knowledge. Note that this may cause problems with Cobol-85, since Cobol-85 can work in both hex and nhex modes.

See Also:

expl nsc link

Copyright © 1996, Thinkage Ltd.