tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] How TCC handlse the scope


From: Dave Dodge
Subject: Re: [Tinycc-devel] How TCC handlse the scope
Date: Mon, 25 Jun 2007 15:14:15 -0400
User-agent: Mutt/1.5.12-2006-07-14

On Sat, Jun 23, 2007 at 12:48:01AM -0400, Rob Landley wrote:
> <nitpick>
> Actually, C assumes it takes all varargs and returns an int.  int blah(...);
> (see "man 3 va_arg".)
> </nitpick>

And C99 removes implicit declarations entirely; calling an undeclared
function in C99 is a syntax error.  And yes it's a bit weird that this
is considered a _syntax_ error rather than something like a constraint
violation, but that's how the Standard words it.

> Way back when (before the Ansi C 89 standard) there were no function
> prototypes, so every function was expected to do the above.  This
> works for a surprising number of things because on a 32-bit
> platform, any pointer can be cast to an int and back so things that
> return pointers work if you return ints.  Basically there was a
> register in which to expect the return value.

Aside: in C89 you do have to be careful about mixing prototypes and
non-prototypes, even on 32-bit platforms.  I was once faced with some
code that worked on SPARC/Solaris but broke bizarrely when compiled on
m68k Domain/OS.  The problem turned out to be a function that was
defined with a prototype but was being called through an implicit
declaration, and had a short in the middle of its parameter list.  The
caller (with no prototype) was promoting the short and passing it on
the stack as four bytes; but the callee (with a prototype) was
expecting an unpromoted two-byte short.  This resulted in the callee
getting very confused about not only the short argument but all of the
arguments that came after it.  It had "worked" on SPARC because the
ABI there normally used fixed-size registers instead of stack space to
pass arguments.

                                                  -Dave Dodge




reply via email to

[Prev in Thread] Current Thread [Next in Thread]