Path: utzoo!utgpu!cunews!mitel!melair!dataco!amodeo From: amodeo@dataco.UUCP (Roy Amodeo) Newsgroups: comp.lang.c Subject: Re: Func Protos with K&R Func Defs Message-ID: <503@dcsun21.dataco.UUCP> Date: 13 Mar 91 18:00:09 GMT References: <1991Mar1.030739.9683@nlm.nih.gov> <4865@goanna.cs.rmit.oz.au> Reply-To: amodeo@dcsun03.UUCP (Roy Amodeo,DC ) Organization: Canadian Marconi Company (Datacomm), Ottawa, Ontario Lines: 90 In article <4865@goanna.cs.rmit.oz.au> ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes: > >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 A2(t1,v1,t2,v2) \ > (t1 v1, t2 v2) > ... > >#else > >#define PROTO(x) () > > ... >#define A2(t1,v1,t2,v2) \ > (v1,v2) t1 v1; t2 v2; > ... > >#endif > >The example then becomes > int tkline A2( > char*, bufP, /* Buffer pointer */ > AREG1 char*, tbufP) /* Token buffer pointer */ > { ... } > >All done by kindness. A problem arises in the following case: int insert( char a[MAX_A], int (*func)( char a[] ) ) { ... } So perhaps you should extend the macro to be #ifdef __STDC__ #define A2( t1, v1, x1, t2, v2, x2 ) \ (t1 v1 x1, t2 v2 x2 ) #else #define A2( t1, v1, x1, t2, v2, x2 ) \ (v1, x1 ) t1 v1 x1; t2 v2 x2; #endif Then my example becomes: int insert( char,a,[MAX_A], int (*, func, ) PROTO(( char a[] )) ) ----------------------------------^^^^^^^ I don't think this will work because the commas inside the brackets are supposed to separate the macro arguments, but I don't think they will because they are in brackets. So perhaps you have to do it with typedefs: typedef int (*intfunc_char) PROTO(( char a[] )); int insert A2( char,a,[MAX_A], intfunc_char, func, ) { ... } which should work. Unfortunately the original example becomes: int tkline A2( char*, bufP,, intfunc_char, func, ) The double commas are obnoxious and errors involving them might be a pain to find. The necessity to typedef function pointers is worse. The best solution is to use all ANSI tools if possible. I wish we could. Just thought you'd like to know what you're getting into. rba iv dataco!amodeo ***--------------------------------------------------------------*** * DISCLAIMER: * * ==========: * * The opinions expressed are solely of the author and do not * * necessarily reflect the opinions of Canadian Marconi Company. * ***--------------------------------------------------------------***