Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo 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

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

    The Pascal calling sequence can be generated from C functions in two
    ways: use the compile-time switch -p, 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 -p has been used (generate Pascal calling conventions
                by default) and you wish to call a C function, you must
                declare that function using cdecl. Note that when
                extended keyword recognition is enabled, all 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 Pascal and Fortran calling/return sequences are
                identical, you can use the pascal keyword when calling
                Fortran code.  Turbo C does not have the redundant
                keyword fortran.

                It is possible to generate 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

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