[comp.lang.c] ANSI/K&R functions in same source

doel@kirkwood.crd.ge.com (01/21/91)

Hi,

I imagine this type of thing has been discussed before, so I apologize
for any repitition.  I write most of my code on a PC using an ANSI
compiler.  One of the biggest plusses of ANSI is of course, the function
prototypes.  However, I also like to use some of the tools available (e.g.
lint) on Unix boxes that don't know about prototypes (when will this
change?).  I have been writing code in the following manner:

in my_decl.h
-------------
#ifdef __STDC__
void func1(int arg1, double arg2);
char *func2(char *arg3);
#else
void func1();
char *func2();
#endif

in my_code.c
------------
#ifdef __STDC__
void func1(int arg1, double arg2)
#else
void func1(arg1,arg2)
int arg1;
double arg2;
#endif

etc...

While this works (i.e. I don't have to run some ansi-to-k&r filter or vice
versa), I imagine that there is a more elegant solution.  Is there a clean
way to write functions which can be compiled immedaitely on ANSI & KR
compilers while retaining function prototypes on the ANSI compilers?

Thanks in advance

Mike

gwyn@smoke.brl.mil (Doug Gwyn) (01/22/91)

In article <15895@crdgw1.crd.ge.com> doel@kirkwood.crd.ge.com () writes:
>Is there a clean way to write functions which can be compiled immedaitely
>on ANSI & KR compilers while retaining function prototypes on the ANSI
>compilers?

/* to permit a single declaration to provide a prototype or not, depending: */
/* Example usage:	extern int myfunc PARAMS((int a, char *b));	*/
#if __STDC__
#define	PARAMS( a )	a
#else
#define	PARAMS( a )	()
#endif