Visual C/C++ and Visual Basic Naming Conventions

Visual C/C++ and Visual Basic preserve case sensitivity in their symbol tables while Fortran by default does not, a difference that requires attention. Fortunately, you can use the Fortran directive ATTRIBUTES ALIAS option to resolve discrepancies between names, to preserve mixed-case names, or to override the automatic conversion of names to all uppercase by the Fortran default naming, or the automatic conversion to all lowercase by Fortran's STDCALL and C naming convention.

Visual C++ uses the same calling convention and argument-passing techniques as C, but naming conventions are different because of Visual C++ decoration of external symbols. When the C++ code resides in a .cpp file (created when you select C/C++ file from the visual development environment), C++ name decoration semantics are applied to external names, often resulting in linker errors. The extern "C" syntax makes it possible for a Visual C++ module to share data and routines with other languages by causing Visual C++ to drop name decoration.

The following example declares prn as an external function using the C naming convention. This declaration appears in Visual C++ source code:

  extern "C" { void prn(); }

To call functions written in Fortran, declare the function as you would in C and use a "C" linkage specification. For example, to call the Fortran function FACT from Visual C++, declare it as follows:

  extern "C" { int __stdcall FACT( int n ); }

The extern "C" syntax can be used to adjust a call from Visual C++ to other languages, or to change the naming convention of Visual C++ routines called from other languages. However, extern "C" can only be used from within Visual C++. If the Visual C++ code does not use extern "C" and cannot be changed, you can call Visual C++ routines only by determining the name decoration and generating it from the other language. Such an approach should only be used as a last resort, because the decoration scheme is not guaranteed to remain the same between versions.

Use of extern "C" has some restrictions:

For more information on the extern "C" linkage specification, see the Microsoft Visual C++ Language Reference.