[2531] in Kerberos_V5_Development

home help back first fref pref prev next nref lref last post

Re: Prototype hell

daemon@ATHENA.MIT.EDU (Jeffrey Hutzelman)
Thu Oct 9 17:04:34 1997

Date: Thu, 9 Oct 1997 17:03:31 -0400 (EDT)
From: Jeffrey Hutzelman <jhutz+@cmu.edu>
Reply-To: Jeffrey Hutzelman <jhutz+@cmu.edu>
To: Ken Hornstein <kenh@cmf.nrl.navy.mil>
Cc: krbdev@MIT.EDU
In-Reply-To: <199710091925.PAA09688@ginger.cmf.nrl.navy.mil>

> Now, I really don't understand the C specifiation that well, so I was
> wondering .... who's at fault here?  Kerberos, or the C compiler?
> I've heard one set of arguments that say old-style function declarations
> always get promoted to a int, which doesn't match a prototype of a short.
> Is that correct?  Pointers from the ANSI C standard would be appreciated,
> as I could use it as ammo.

Unfortunately, my coworker who has a copy of the standard has gone
home for the day, so I can't look up what it says.  However, my
recollection is that char and short arguments _always_ get promoted
to an int.  On the other hand, the prototype should say what you
really mean, not what you're assuming the compiler will promote to.
If a function takes a short as an argument, then prototype it as
taking a short, and define it as taking a short:

#ifdef __STDC__
int foo(int, short, int);
#endif

.
.
.

#ifdef __STDC__
int foo(int a, short b, int c)
#else
int foo(a, b, c)
int a, c;
short b;
#endif
{
  return a + b + c;
}



Another approach I often use is to say something like, "To hell with
this idiocy.  This is 1997; if you can't find an ANSI-compliant
compiler, you just lose," and proceed to write code with the assumption
that ANSI features like prototypes are _always_ available.

-- Jeff

home help back first fref pref prev next nref lref last post