Func Protos with K&R Func Defs

Jonathan Arnold jdarnold at pondsquid.mv.com
Sat Mar 2 01:38:51 AEST 1991


usenet at nlm.nih.gov (usenet news poster) writes:
> In article <11614 at jpl-devvax.JPL.NASA.GOV> david at jpl-devvax.JPL.NASA.GOV (Dav
> #ifdef _FUNCTION_PROTOTYPES
> #define PROTO(x) x
> #else
> #define PROTO(x)
> #endif
>   Warren Gish                           phone:  (301) 496-2475

A friend and I wrote a medium-sized program and ran into this exact
problem - he has a fairly old, vanilla UNIX cc, without ANSI, while I'm
using Turbo C++ V1.0 and didn't want to give up prototypes.  This is the
solution we came up with (quite similar to the above):

#ifdef  USE_PROTOS
#define PROTO( def )    def
#define NOARGLIST       ( void )
#define ARGLIST( args ) (
#define NFARG( def )    def,
#define FARG( def )     def )
#else
#define PROTO( def )    ()
#define NOARGLIST       ()
#define ARGLIST( args ) args
#define NFARG( def )    def;
#define FARG( def )     def;
#endif

As examples:
      PROTOTYPES
      ----------
int tkline PROTO( (char *, char *, char **, int, char *, char *) );
char *gettoken PROTO( (char *, char *, int, char *, char *) );
int gettkline PROTO( ( FILE *, char *, int, int *, char **, int) );
int getline PROTO( (FILE *, char *, int) );

      ACTUAL FUNCTIONS DECLARATIONS
      -----------------------------
int tkline ARGLIST( ( bufP, tbufP, tokv, tokmax, vsepP, isepP ) )
	NFARG ( char *bufP )		/* Buffer ptr */
	NFARG ( AREG1 char *tbufP)	/* Token buffer pointer */
	NFARG ( AREG2 char **tokv)	/* Arg vectors */
	NFARG ( int tokmax)		/* Max # tokens */
	NFARG ( char *vsepP)		/* Visible separators */
	FARG ( char *isepP)		/* Invisible separators */
{
   .....
}


and

int gettkline ARGLIST( (fP, bufP, bufsize, tokcP, tokv, tokmax) )
	NFARG( FILE *fP )		/* Input file ptr */
	NFARG( char *bufP )		/* Buffer ptr */
	NFARG( int bufsize )	/* Room in buffer */
	NFARG( int *tokcP )		/* Variable to hold token count */
	NFARG( char **tokv )		/* Arg vectors */
	FARG( int tokmax )		/* Max # tokens */


It's is kind of ugly, but it works and you get full function prototyping. 
What does everyone out there think of this method?


--
Jonathan Arnold                  | Blue Sky Productions
Bus. Phone: (603)894-5336        | 59 Stiles Rd, Ste. 106
Home Phone: (617)335-5457        | Salem NH 03079
uucp: jdarnold at pondsquid.MV.COM
  or ...{decvax|elrond|harvard}!zinn!pondsquid!jdarnold



More information about the Comp.lang.c mailing list