Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C - <b>fortran fortran calling sequence modifier</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
fortran                  Fortran Calling Sequence Modifier

    MS-Fortran uses a different calling sequence than MS-C. MS-Fortran
    passes function arguments left to right, and does not allow variable-
    length argument lists. The called function has the responsibility for
    removing the arguments from the stack, rather than having the caller
    do so when control returns.

    The Fortran calling sequence can be generated from C functions in two
    ways:  use the compile-time switch /Gc, which makes the Fortran
    sequence the default for all enclosed calls and function definitions;
    or explicitly override the standard C calling sequence by using the
    fortran keyword on specific function declarations or definitions.

    When C generates a function call, by default, it adds a leading
    underscore to the function name and declares that as an external.  It
    also preserves the casing of the name.  When the fortran keyword is
    used, the underscore is not added and the name is converted to all
    uppercase to be compatible with MS-Fortran compiler code generation.
    The same occurs when fortran is used with external variables.

      Notes:    If a C function calls an MS-Fortran routine, the
                declaration of the Fortran function must include the
                fortran keyword (or /Gc must be in effect) so that the C
                compiler does not clean up the call stack on return from
                the Fortran routine.  If the fortran keyword is omitted
                (and the /Gc is not used either), both the caller and the
                callee will pop the stack, handing you an error.  On the
                other hand, to ensure that an MS-C function being called
                from MS-Fortran cleans up its own call stack, you must
                use the fortran keyword in the MS-C function's definition
                (or use the /Gc switch).

                If /Gc has been used and you wish to call a C function,
                you must declare that function using cdecl. Note that
                when extended keyword recognition is enabled, all of the
                standard headers declare their library routines to have
                the cdecl attribute, so it is not necessary for you to do
                this (provided you #include the appropriate header before
                calling the library function).

                Since the MS-Fortran and MS-Pascal calling/return
                sequences are identical, the fortran and pascal keywords
                can be interchanged.  Logically, however, it makes sense
                to use fortran when you are calling an MS-Fortran routine
                and pascal when you are calling MS-Pascal code.

                It is possible to generate MS-Fortran style calls and
                never call or be called by a Fortran routine.  The
                advantage of this is that such calls are generally more
                efficient than C calls. This is because stack cleanup is
                only done in one place--the called routine--rather than
                every place from which the function is called.

  -------------------------------- Example ---------------------------------

           int fortran fp(a, b, c)
           int a;
           long b;
           double c;
           {
                ...
           }

           int fortran table[100];

           main()
           {
                extern int fortran fp();
                int i;

                i = fp(1, 2L, 1.2);
           }

See Also: cdecl Pascal Switches

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson