Rational Developer for System z
PL/I for Windows, Version 7.6, Programming Guide

Understanding linkage considerations

On Windows, there are three primary linkages that the PL/I compiler supports: OPTLINK, CDECL, and STDCALL. On Windows, all the system services use the STDCALL linkage.

These linkages differ in their parameter passing conventions:

The PL/I for Windows compiler interprets any specification of the SYSTEM linkage as if the STDCALL linkage were intended. The VisualAge C compiler does the same.

On Windows, all external names are decorated. If the external attribute does not specify a name, the name decoration depends on the linkage:

One consequence of these name decorations is that if a caller of a routine specifies the wrong linkage for that routine, the program fails to link.

So far, the discussion of name decoration has applied only to routines for which the external attribute did not specify a name. It also applies when the external attribute specifies a name that differs only in case from the declared name. In these situations, the name specified as part of the external attribute is decorated.

For example, given the following declare, the name that the linker sees is ?getenv.

  dcl getenv ext('getenv')
     entry( char(*) varz byaddr nonasgn )
     returns( pointer )
     options( nodescriptor linkage(optlink) );

Similarly, for the following declare (for the Windows system routine that loads a DLL), the name specified as part of the external attribute is decorated, and the linker sees the name as _LoadLibraryA@4.

  dcl loadlibrarya  ext('LoadLibraryA')
     entry( char(*) varz byaddr nonasgn )
     returns( pointer byvalue )
     options( linkage(stdcall) nodescriptor );

If, however, a name is specified as part of the external attribute and that name differs from the declared name by more than its case, then no name decoration occurs.

For example, given the following declare, no name decoration occurs and the name that the linker sees is ?getenv.

  dcl getenv ext('?getenv')
   entry( char(*) varz byaddr nonasgn )
   returns( pointer )
   options( nodescriptor linkage(optlink) );

Performing name decoration yourself as illustrated in this last example usually makes your code less portable. For instance, only the first declare for getenv in the preceding examples is valid for Windows and AIX.


Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)