Function prototypes
Doug Schmidt
schmidt at zola.ics.uci.edu
Sun Apr 30 05:18:17 AEST 1989
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 at ics.uci.edu |
With loot in your pocket. | office: (714) 856-4043 |
More information about the Comp.lang.c
mailing list