Func Protos with K&R Func Defs

David E. Smyth david at jpl-devvax.JPL.NASA.GOV
Fri Mar 1 08:01:03 AEST 1991


scs at adam.mit.edu (Steve Summit) writes that ANSI C may well stop
supporting old-style function definitions at some time in the future.
Therefore he recommends that writing K&R style definitions is probably
a bad idea in the long term.

Well, the problem is this: ANSI is not portable, K&R is.

Oh, I know I know I know.  But hear me out:

I actually wanted to use ANSI for the Widget Creation Library, and
initially implemented it using ANSI.  Problem:  Many, many people could
not compile it!  So, I went back to K&R.  Now its portable.  The reason
I provide the ANSI function protos in decls is just in case somebody,
somewhere ONLY has and ANSI compiler (which of course still understands
K&R function definitions).

It is true that Wcl is not totally portable, and perhaps one of the
problems is that I may not have been careful enough somewhere in making
certain that I'm never using non-promoted arguments to functions.

It seems that one *must* write code which works with or without
prototypes just to be sure that it is portable.  I.e., perhaps the
correct approach is that suggested by the person who write that
whenever you have ANSI prototypes, you also have K&R declarations as
well as K&R definitions, is correct.

Perhaps even more important that portability is simply interoperability
on a single platform.  If your functions work identically with or
without prototypes (int-size or double arguments only) then people can
mix libraries and applications which have been built using different
compilers.

So, I'll bet that if a C compiler did NOT compile K&R C, it probably
would in fact be alot less useful than one that did.  Since compilers
are generally written by people who for one reason or another want the
compiler to be useful to many people, I doubt if we will see good
compilers which understand only ANSI declarations and definitions.

I could very, very, very easily be wrong.  I'm not a prophet, like
Saddam or anything ;^)

-------------------------------------------------------------------------
David Smyth				david at jpl-devvax.jpl.nasa.gov
Senior Software Engineer,		seismo!cit-vax!jpl-devvax!david
X and Object Guru.			(818)393-0983
Jet Propulsion Lab, M/S 230-103, 4800 Oak Grove Drive, Pasadena, CA 91109
------------------------------------------------------------------------- 
	One of these days I'm gonna learn:  Everytime I throw
	money at a problem to make it disappear, the only thing
	that disappears is my money...
-------------------------------------------------------------------------



More information about the Comp.lang.c mailing list