Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!usc!orion.cf.uci.edu!uci-ics!zola.ics.uci.edu!schmidt From: schmidt@zola.ics.uci.edu (Doug Schmidt) Newsgroups: comp.lang.fortran,comp.lang.c Subject: Function prototypes Message-ID: <12942@paris.ics.uci.edu> Date: 29 Apr 89 19:18:17 GMT References: <2846@tank.uchicago.edu> <5785@cbnews.ATT.COM> <10087@smoke.BRL.MIL> <2692@tekcae.CAX.TEK.COM> <307@cbnewsh.ATT.COM> <1399@uw-entropy.ms.washington.edu> <8145@pucc.Princeton.EDU> Sender: news@paris.ics.uci.edu Reply-To: Doug Schmidt Distribution: usa Organization: University of California at Irvine: ICS Dept. Lines: 49 Xref: utzoo comp.lang.fortran:1990 comp.lang.c:18183 I'm about to port a C++ program to C. The original C++ program uses function prototypes heavily. It seems ashame to remove all the extra type checking, but the port must run on both ANSI and non-ANSI C compilers. Therefore, 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. Dealing with external declarations seems fairly straight-forward: /* prototype.h */ #ifdef __STDC__ #define P(X) X #else #define P(X) #endif Then all extern decls could look like: #include "prototype.h" int foo (P(int foobar)); and the preprocessor will correctly substitute in a prototype for ANSI compilers or do nothing, for non-ANSI compilers. This should work in general, right? However, for function definitions things get messy. For example, I could use the old: #ifdef __STDC__ int foo (int foobar) #else int foo (foobar) int foobar; #endif trick, but this gets ugly real quick. Does anyone have a set of macros that helps simplify and beautify the process?! thanks, Doug -- On a clear day, under blue skies, there is no need to seek. And asking about Buddha +------------------------+ Is like proclaiming innocence, | schmidt@ics.uci.edu | With loot in your pocket. | office: (714) 856-4043 |