prototypes, old and new compilers

William E. Davidsen Jr davidsen at steinmetz.ge.com
Sat Dec 17 05:35:16 AEST 1988


In article <136 at bms-at.UUCP> stuart at bms-at.UUCP (Stuart Gathman) writes:

| Does anyone have a parser that can recognize function prototypes and
| 
| 	1) replace them with comments
| 		or
| 	2) strip the optional identifiers
| 		or
| 	3) add or remove the trailing '...'

  I will share with you a little technique I use for allowing procedure
declarations to hold what I want without having to rewrite the source
code. Be warned, this addresses (1) and (2), and most of (3), but it's
really ugly. Also, some compilers which take prototypes with type info
don't accept elipsis, while others do. The comment shows where I change
this if need be.
________________________________________________________________

#define NoProto		1
#define TypesOnly	2
#define FullANSI	3

#ifndef	P
#define P NoProto
#endif

#if	P == NoProto
#define Param(x) ()
#endif
#if	P == TypesOnly
#define Param(x) x
#define Ptype(x, y) x
#define Pelipsis			/* is this one right for you? */
#endif
#if	P == FullANSI
#define Param(x) x
#define Ptype(x,y) x y
#define Pelipsis ,...
#endif

int someproc Param((Ptype(int *,x),Ptype(long,ypos)));
int myprintf Param((Ptype(char *, format) Pelipsis));
________________________________________________________________

This will doubtless start a macro war, in which ten people will tell me
there's a better way, and another ten will ignore the comment about
variable arguments and tell me Pelipsis has the wrong value for
TypesOnly.

Oh well, I hope this actually helps someone.
-- 
	bill davidsen		(wedu at ge-crd.arpa)
  {uunet | philabs}!steinmetz!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me



More information about the Comp.lang.c mailing list