Func Protos with K&R Func Defs

brian_helterline brianh at hpcvia.CV.HP.COM
Sat Mar 2 04:36:57 AEST 1991


scs at adam.mit.edu (Steve Summit) writes:
:In article <11614 at jpl-devvax.JPL.NASA.GOV> david at jpl-devvax.JPL.NASA.GOV (David E. Smyth) writes:
:>I do this all the time:
:>
:>    #ifdef _FUNCTION_PROTOTYPES
:>    extern void WcWidgetCreation ( Widget root );
:>    #else
:>    extern void WcWidgetCreation();
:>    #endif
:>
:>    void WcWidgetCreation ( root )
:>        Widget       root;
:>    {
:>        ...
:>
:>This seems like the easiest way to use prototyped function declatations
:>when your compiler supports it, and K&R function definitions in any
:>case.  Then only the *.h files need to have #ifdef's.

:Indeed, and this is essentially the technique I use.  (In
:external function declarations, I omit the #else, and leave the
:nonprototyped form visible to both kinds of compilers, which adds
:a bit of consistency checking.)

:This technique works well, although there are two important
:caveats which require some care in applying, which is why mixing
:prototyped declaration with "old style" definitions is not
:generally recommended.
:
:The two caveats are:
:
:     1.	The prototype declaration must use the widened types (int
:	or double) for any parameters in the old-style definition
:	which are "narrow" (char, short, or float).
:
I also use prototypes with "old-stye" definitions but I let the compiler
generate the prototypes and it uses the widened types when necessary so
I don't have to worry about it. e.g.

Function( arg1 )
float arg1;
{return 0}

would produce the prototype: int Function( double arg1 );

[caveat 2 deleted]



More information about the Comp.lang.c mailing list