Your programs must agree on the calling convention and the naming convention; they must also agree on the order in which they pass parameters. It is important that your routines send parameters in the same way to ensure proper data transmission and correct program results.
Microsoft compilers support three methods for passing a parameter:
Method | Description |
Near reference | Passes a variable's near (offset) address. This address is expressed as an offset from the default data segment. |
This method gives the called routine direct access to the variable itself. Any change the routine makes to the parameter changes the variable in the calling routine. | |
Far reference | Passes a variable's far (segmented) address. |
This method is similar to passing by near reference, except that a longer address is passed. This method is slower than passing by near reference, but is necessary when you pass data that is outside the default data segment. (This is an issue in BASIC or Pascal only if you have specifically requested far memory.) | |
Value | Passes only the variable's value, not its address. |
With this method, the called routine knows the value of the parameter but has no access to the original variable. Changes to a value passed by a parameter have no affect on the value of the parameter in the calling routine. |
These different parameter-passing methods mean that you must consider the following when programming with mixed languages:
You need to make sure that the called routine and the calling routine use the same method for passing each parameter (argument). In most cases, you will need to check the parameter-passing defaults used by each language and possibly make adjustments. Each language has keywords or language features that allow you to change parameter-passing methods.
You may want to choose a specific parameter-passing method rather than using the defaults of any language.
Table 11.2 summarizes the parameter-passing defaults for each language.
Table 11.2 Parameter-Passing Defaults
Language | Near Reference | Far Reference | By Value |
BASIC | All | —- | —- |
C/C++ | Near arrays | Far arrays | All data except arrays |
FORTRAN | All (medium model) | All (large model) | With attributes1 |
Pascal | VAR, CONST | VARS, CONSTS | Other parameters |
1 When a PASCAL or C attribute is applied to a FORTRAN routine, passing by value becomes the default.