Function prototypes

Wayne A. Throop throopw at bert.dg.com
Mon May 8 12:21:12 AEST 1989


> schmidt at zola.ics.uci.edu (Doug Schmidt)
> I'd like to know whether anyone has devised a
> useful set of preprocessor conventions that allow relatively
> transparent conversion between compilers that accept prototypes and
> those that don't.

There are many tradeoffs to be made.  What I finally ended up using
for situations where non-ansi compilers had to be accomodated has
some drawbacks in that it requires some redundancy and prevents
accurate typechecking of some of it.  But it doesn't look too
terribly awful, and it allows declaration of routines and contracts.

It involves three macros, P, PT, and PP.  The first is used in declaring
functions.  Where one might declare

    int foo( short bar, long bletch )
    {
        ...
    }

one would write

    int foo P(( bar, bletch ),
                short bar PP
                long  bletch )
    {
        ...
    }
    
And in place of

    int (*foo)( short, long );

one would write

    int (*foo) PT(( short, long ));

The definitions of the macros is left as an excersize to the reader.
It isn't too difficult, basically setting the appropriate separators
for PP, deciding whether to expand the argument to PT, and finally
deciding whether to expand the first argument to P and what punctuation
to put around the second one.

--
If it could be demonstrated that any complex organ existed which coult not
possibly have been formed by numerous, successive, slight modifications,
my theory would absolutely break down.
                              --- Charles Darwin
--

Wayne Throop      <the-known-world>!mcnc!rti!xyzzy!throopw



More information about the Comp.lang.c mailing list