cdecl and pascal keywords

Rahul Dhesi dhesi%cirrusl at oliveb.ATC.olivetti.com
Fri Jan 4 16:25:39 AEST 1991


In <26075 at uflorida.cis.ufl.EDU> jdb at reef.cis.ufl.edu (Brian K. W. Hook) writes:

>...but I was wondering whether there is a NOTICEABLE difference
>in speed and size of program that uses PASCAL declarations...

This belongs in comp.lang.pascal, does it not?

Seriously, please don't assume that comp.lang.c readers will be able to
answer questions about nonstandard extensions of the C programming
language.  The "pascal" keyword is used by MS-DOS-specific compilers,
and a better place to ask the question will be one of the MS-DOS
newsgroups.

However...

The effect of using the "pascal" keyword is to tell the compiler that
it need not assume that traditional C style function calls, with a
posibly variable number of parameters, will be used.  The compiler can
thus generate code that allows the called function to pop the stack
before it returns, rather than inserting stack-popping code after each
call to each function.  Difference in speed:  probably not noticeable.
Difference in code size: a few bytes (let's say about 2 bytes) saved
each time any function is called.  If a function is called 10 times,
that means 20 bytes saved by making that function a "pascal" function.

In theory, there is no need for a "pascal" keyword if you're using ANSI
C, since the compiler knows whether or not a prototype is in scope, and
can generate efficient or inefficient code accordingly.  In practice,
it seems (unverified suspicion) that most MS-DOS compilers don't take
advantage of the presence of ANSI C prototypes for such optimization
but do take advantage of the "pascal" keyword.  This could be because
of the fear that the user might link the object code resulting from his
C source with an assembly language program, or out of the knowledge
that most MS-DOS users don't use "lint" and can therefore not check
function calls for consistency across files.
--
History never         |   Rahul Dhesi <dhesi%cirrusl at oliveb.ATC.olivetti.com>
becomes obsolete.     |   UUCP:  oliveb!cirrusl!dhesi



More information about the Comp.lang.c mailing list