Compiling with Correct Memory Models

With BASIC, FORTRAN, and Pascal, no special options are required to compile source files that are part of a mixed-language program.

Summary: With C or C++, not all memory models are compatible with other languages.

BASIC, FORTRAN, and Pascal use only far (segmented) code addresses. Therefore, you must use one of two techniques with C or C++ programs that call one of these languages: compile the C or C++ modules in medium, large, or huge model (using the /AX command-line options), because these models also use far code addresses; or apply the __far keyword to the definitions of C or C++ functions you make public. If you use the /AX command-line option to specify medium, large, or huge model, all your function calls become far by default. This means you don't have to declare your functions explicitly with the __far keyword.

Choice of memory model affects the default data pointer size in C, C++, and FORTRAN, although this default can be overridden with the __near and __far keywords. With C, C++, and FORTRAN, choice of memory model also affects whether data objects are located in the default data segment; if a data object is not located in the default data segment, it cannot be passed by near reference.

For more information about code and data address sizes in C and C++, refer to Chapter 4, “Managing Memory in C,” and Chapter 5, “Managing Memory in C++.”