Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Linkage conventions specific to C and C++

&pagelevel(3)&pagelevel

Some of the specific conventions to be observed in C/C++ in addition to the ILCS conventions described in the CRTE User Guide are outlined below.

Parameter passing by value

In C/C++, parameters are passed “by value” (as defined in the respective language standards). The parameter list therefore contains the values of the individual parameters. This form of parameter passing is possible only if all objects to be linked are C and C++ objects.

The internal structure of the parameter list is described in section “Implementationdefined behavior based on the ANSI/ISO C standard”.

The following actions are necessary for linkage to objects in other languages:

  • When a routine in some other language is called, the address of the data element to be transferred must be specified (e.g. &par). Technically speaking, the address of the data element is then passed “by value”.

  • If a C/C++ routine is called from a routine in another language, the formal parameters in C and C++ must be declared as pointers to the data elements to be transferred, e.g. f(T *par).

Passing of floating-point numbers

The following points must be noted with respect to the passing of floating-point numbers when specifying linkage from K&R C to C89, C11 or C++ objects:
In K&R mode, float values are always passed as double. In the other modes, float values are only passed as double if no prototype declaration exists; otherwise, they are actually passed as float values.
In C++ mode, float values are always passed unconverted.

The proper transfer of floating-point numbers between K&R C and C89, C11 or C++ can only be guaranteed if floating-point parameters are declared double in the C89, C11 or C++ program.

Passing function return values

In the case of a structure function, the result structure is copied to the parameter list, and a pointer to the parameter list is supplied in R1.