Func Protos with K&R Func Defs
Roy Amodeo
amodeo at dataco.UUCP
Thu Mar 14 04:00:09 AEST 1991
In article <4865 at goanna.cs.rmit.oz.au> ok at 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. *
***--------------------------------------------------------------***
More information about the Comp.lang.c
mailing list