Curious about function prototypes...

Wayne A. Throop throopw at xyzzy.UUCP
Thu Jun 16 02:58:18 AEST 1988


> chris at mimsy.UUCP (Chris Torek)
>> gunars at spsspyr.UUCP (Gunars V. Lucans)
>>... For declarations, [...]
>>	void foo PARMS( (int arg1, char *arg2) );
> I use something like this already [...]
>>Definitions are another matter.
> Indeed.
>>Is there an alternative (other than not using prototypes at all) to:
>>	[... using ifdef around each argument of a function ...]
> I think I prefer [... to put the ifdefs around the whole definition ...]
> 	#ifdef PROTO_OK
> 	void foo(int arg1, char *arg2)
> 	#else
> 	void
> 	foo(arg1, arg2)
> 		int arg1;
> 		char *arg2;
> 	#endif
> 	{
> even if it does name everything twice (or three times!).

I defined three macros, PT (prototype), PF (prototype formals), and PP
(prototype punctuation).  Thus, for declarations, the familiar

        void *foo PT(( char *, int ));

and for the more troublesome declarations, the odd-looking-at-first

        void foo PF(( cp, i),
                    char *cp PP
                    int i PP )
        {
                /* body */
        }

This has the same amount of redundancy as the old-style declarations.
On the other hand, it has the new requirement that the variables be in
the correct order in both lists instead of just in the first, but this
doesn't seem too onerous.

I'll leave the definitions of the macros as excersizes for the reader...
they aren't too difficult.  I do have one question for the net, however.
Clearly, we can see that PP expands to either a comma or a semicolon.
Are there any preprocessors that would barf on this?  I haven't
discovered any so far, knock plastic.

--
Nature abhors a hero.
                        --- Solomon Short
-- 
Wayne Throop      <the-known-world>!mcnc!rti!xyzzy!throopw



More information about the Comp.lang.c mailing list