selectively enabling prototypes

here kitty, kitty... daveb at llama.Ingres.COM
Tue Aug 14 03:24:52 AEST 1990


It's a mess.  The PROTO style of macro is convenient to write, but
violates one of the secret laws of C style: "Thou shalt not change the
syntax of the language with macros."  Using them messes up all sorts of
syntax-sensitive tools, and is confusing to the unitiated.

The solution of #ifdef around all the specific cases is bugly and a pain
to use, but it is correct and portable when done correctly.

Numberous people believe tha answer is really to write a filter that
turns ANSI code into Classic-C code, inserting all the casts into
function calls as needed.  This would be neet, but nobody knows of the
existance of such a program.  *sigh*  The person who writes one and
posts it will be *very* popular!

-dB

In <493 at mtndew.Tustin.CA.US> friedl at mtndew.Tustin.CA.US (Steve Friedl) writes:
>Hi folks,
>
>     I like to use function prototypes when possible, so in my
>header files I do something like this:
>
>	#ifdef	USE_PROTO
>	#  define	PROTO(name, args)	name args
>	#else
>	#  define	PROTO(name, args)	name ( )
>	#endif
>
>	extern PROTO(int printf, ( const char *, ... ) );
>	extern PROTO(char *strcpy, ( char *, const char * ) );
>
>and so on (note: I know that printf and strcpy are in other
>headers, I'm just using familiar examples).  I have been doing
>this for about two years and have been really happy with it.
>However, I have seen it done "the hard way":
>
>	#ifdef	USE_PROTO
>	  extern int printf(const char *, ... );
>	  extern char *strcpy(char *, const char * );
>	#else
>	  extern int printf()
>	  extern char *strcpy();
>	#endif
>
>This looks like a real maintenance nightmare, but some of the
>people who do it are people I respect, so I gotta wonder if they
>know something that I don't know on this one.  Are there any
>gotchas on doing it with the flavor of the way I've done it?
>
>Note: I do know that things like signal() won't fit into my mold,
>but these are so much in the minority that I don't mind doing those
>few "the hard way".
>
>     Steve
>
>--
>Stephen J. Friedl, KA8CMY / Software Consultant / Tustin, CA / 3B2-kind-of-guy
>+1 714 544 6561  / friedl at mtndew.Tustin.CA.US  / {uunet,attmail}!mtndew!friedl
>
>If Larry Ellison says it, it must be true.

Ahem.
"Bottom of the 4th, Cooper pitching"	- tibetan baseball
David Brower:  daveb at rtech^H^H^H^H^Hingres.comd



More information about the Comp.lang.c mailing list