Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!snorkelwacker.mit.edu!think.com!spool.mu.edu!sol.ctr.columbia.edu!samsung!pondsquid!jdarnold From: jdarnold@pondsquid.mv.com (Jonathan Arnold) Newsgroups: comp.lang.c Subject: Re: Func Protos with K&R Func Defs Message-ID: Date: 1 Mar 91 14:38:51 GMT References: <1991Mar1.030739.9683@nlm.nih.gov> Organization: Blue Sky Productions, Salem NH Lines: 71 usenet@nlm.nih.gov (usenet news poster) writes: > In article <11614@jpl-devvax.JPL.NASA.GOV> david@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@pondsquid.MV.COM or ...{decvax|elrond|harvard}!zinn!pondsquid!jdarnold