Func Protos with K&R Func Defs
Richard A. O'Keefe
ok at goanna.cs.rmit.oz.au
Sun Mar 3 16:31:22 AEST 1991
In article <g8w5X2w163w at pondsquid.mv.com>, jdarnold at pondsquid.mv.com (Jonathan Arnold) writes:
> usenet at nlm.nih.gov (usenet news poster) writes:
[about a way of coding for both ANSI and Classic C, with examples]
> 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 */
> It is kind of ugly, but it works and you get full function prototyping.
> What does everyone out there think of this method?
That it is redundant when there is no need at all for redundancy.
All you have to do is take your ANSI C headers, stick a few more commas
in, and add an identifier:
#ifdef __STDC__
#define PROTO(x) x
#define A1(t1,v1) \
(t1 v1)
#define A2(t1,v1,t2,v2) \
(t1 v1, t2 v2)
#define A3(t1,v1,t2,v2,t3,v3) \
(t1 v1, t2 v2, t3 v3)
#define A4(t1,v1,t2,v2,t3,v3,t4,v4) \
(t1 v1, t2 v2, t3 v3, t4 v4)
#define A5(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
(t1 v1, t2 v2, t3 v3, t4 v4, t5 v5)
#define A6(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
(t1 v1, t2 v2, t3 v3, t4 v4, t5 v5, t6 v6)
#else
#define PROTO(x) ()
#define A1(t1,v1) \
(v1) t1 v1;
#define A2(t1,v1,t2,v2) \
(v1,v2) t1 v1; t2 v2;
#define A3(t1,v1,t2,v2,t3,v3) \
(v1,v2,v3) t1 v1; t2 v2; t3 v3;
#define A4(t1,v1,t2,v2,t3,v3,t4,v4) \
(v1,v2,v3,v4) t1 v1; t2 v2; t3 v3; t4 v4;
#define A5(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
(v1,v2,v3,v4,v5) t1 v1; t2 v2; t3 v3; t4 v4; t5 v5;
#define A6(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
(v1,v2,v3,v4,v5) t1 v1; t2 v2; t3 v3; t4 v4; t5 v5; t6 v6;
#endif
The example then becomes
int tkline A6(
char*, bufP, /* Buffer pointer */
AREG1 char*, tbufP, /* Token buffer pointer */
AREG2 char**,tokv, /* Arg vectors */
int, tokmax, /* Max # of tokens */
char*, vsepP, /* Visible separators */
char*, isepP) /* Invisible separators */
{ ... }
All done by kindness.
--
The purpose of advertising is to destroy the freedom of the market.
More information about the Comp.lang.c
mailing list