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>pascal pascal calling sequence modifier</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
pascal                   Pascal Calling Sequence Modifier

    MS-Pascal uses a different calling sequence than MS-C. It 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 Pascal calling sequence can be generated from MS-C functions in
    two ways: use the compile-time switch /Gc, which makes the Pascal
    calling sequence the default for all enclosed calls and function
    definitions;  or override the default C calling sequence explicitly
    by using the pascal keyword on given function declarations or
    definitions.

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

      Notes:    If an MS-C function calls an MS-Pascal routine, the
                declaration of the Pascal function must include the
                pascal keyword (or /Gc must be in effect) so that the C
                compiler does not clean up the call stack on return from
                the Pascal routine. If the pascal 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-Pascal cleans up its own call stack, you must use
                the pascal 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; it is not therefore necessary for
                you to do so (provided you #include the appropriate
                header before calling the library function).

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

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

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

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

           int pascal table[100];

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

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

See Also: cdecl fortran Switches

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