Mail Archives: djgpp-workers/1998/06/16/04:23:31
Charles Marslett wrote:
>
> Vik Heyndrickx wrote:
> >
> > If I'm correct, the compiler assumes the default when a prototype is
> > omitted. Since the default is ``int'', isn't omitting a prototype
> > equally as bad as providing some prototype?
>
> Not quite. If you provide a prototype, then you cannot override
> it with another (or I don't know how you undef a prototype). While
> if you omit the prototype, you can define it later so long as the
> function is not referenced before the prototype definition.
Suppose you have somewhere in a file the following definition
double foo (double a, unsigned r)
{
while (r--)
a += a;
return a;
}
Suppose you have in ***another file*** a call to this function but no
prototype was given yet:
double r = foo (7, 3);
Since this 7 is an integral constant and no floating point constant it
will occupy only #sizeof(unsigned) number of bytes on the stack while
``foo'' expects 8 bytes (a double). As a result it won't work.
Second example:
Suppose that foo_XQ is a function that is available among different
platforms, but it tends to have a different interface on many platforms
(POSIX's arrows missed it).
A function declared (and defined) in one file as:
void *foo_XQ (void *, int);
In another file (originally written for another platform, on which the
function is declared ``void *foo_XQ (int,void *)'') it is assumed foo_XQ
will be defined in DJGPP, but DJGPP provides no prototypes for it:
void *p;
void *r = foo_XQ (7, p);
I'd bet this doesn't work.
--
\ Vik /-_-_-_-_-_-_/
\___/ Heyndrickx /
\ /-_-_-_-_-_-_/ Knight in the Order of the Unsigned Types
- Raw text -