Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!elroy.jpl.nasa.gov!sdd.hp.com!hp-pcd!hpcvia!brianh From: brianh@hpcvia.CV.HP.COM (brian_helterline) Newsgroups: comp.lang.c Subject: Re: Func Protos with K&R Func Defs Message-ID: <31530037@hpcvia.CV.HP.COM> Date: 1 Mar 91 17:36:57 GMT References: <11614@jpl-devvax.JPL.NASA.GOV> Organization: Hewlett-Packard Co., Corvallis, Oregon Lines: 46 scs@adam.mit.edu (Steve Summit) writes: :In article <11614@jpl-devvax.JPL.NASA.GOV> david@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]