Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!tut.cis.ohio-state.edu!purdue!decwrl!crltrx!decvax!mcnc!rti!sheol!throopw From: throopw@sheol.UUCP (Wayne Throop) Newsgroups: comp.lang.c Subject: Re: ANSI/Non-ANSI Function Declaration Macros Summary: here's what I use when I must, despite the bletcherosity Message-ID: <0300@sheol.UUCP> Date: 17 Dec 89 14:19:18 GMT References: <4603@itivax.iti.org> <244@isgtec.UUCP> <22402@princeton.Princeton.EDU> <248@isgtec.UUCP> Lines: 57 > peter@isgtec.UUCP (Peter Curran) > First, I assume that, in ANSI, the following are exactly equivalent: > void func (char c, short n) {...} > and > void func (c, n) char c; short n; {...} > They are just different syntax for the same thing. I would like to be > corrected if I have misunderstood this. I am pretty sure that Peter has indeed misunderstood this. A prototype declaration must be matched with a prototype definition. I no longer have a copy of the standard directly to hand, but K&RII have some things to say about it that make me quite sure. > My prototype here would be void func P((char c, short n)); In order to make the definitions and declarations agree, I use a more complicated scheme involving the three macros PT, PF, and PP, standing for "prototype", "protype function", and "prototype punctuation". This has been known to make people barf, though compilers seem to like it just fine. So, beware when reading on: return_type func PT((type1 arg1, type2 arg2, type3 arg3)); ... return_type func PF((arg1, arg2, arg3), type1 arg1 PP type2 arg2 PP type3 arg3 ) { ... } Now, P, PF and PP have the obvious definitions, which I'll give below. They can be put in "protomac.h" and largely forgotten about. This scheme does have the problem that you MUST have the arguments in the correct order, and don't change your mind between the first (typeless) and second (typed) list of arguments. This is not horribly more odious than bare K&R style declarations, so I live with it, and await the day when K&R-only implementations are rare enough to dispense with the charade. protomac.h: #ifndef PF #ifdef __STDC__ #define PF(names,types) (types) #define PT(types) types #define PP , #else #define PF(names,types) names types; #define PT(types) () #define PP ; #endif #endif -- Wayne Throop !mcnc!rti!sheol!throopw or sheol!throopw@rti.rti.org