Xref: utzoo comp.lang.c:12126 comp.sys.ibm.pc:18422 Path: utzoo!utgpu!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!agate!eos!ames!mailrus!uflorida!novavax!proxftl!bill From: bill@proxftl.UUCP (T. William Wells) Newsgroups: comp.lang.c,comp.sys.ibm.pc Subject: Re: Function declarations (was: MSC v5.1 Bug???) Message-ID: <619@proxftl.UUCP> Date: 26 Aug 88 01:06:03 GMT References: <10102@genrad.UUCP> <11879@iuvax.cs.indiana.edu> <5680@rpp386.UUCP> <6314@haddock.ima.isc.com> Reply-To: bill@proxftl.UUCP (T. William Wells) Organization: Proximity Technology, Ft. Lauderdale Lines: 48 Summary: Expires: Sender: Followup-To: Distribution: Keywords: A random point on prototypes: we have the need to include prototypes in our code while still being able to compile the code with compilers that did not support prototypes. The solution is this: first, all function arguments are of a type for which the argument widening action is null. (ints are OK, short is not.) Second, we have, in a global include file, something like this: /* Configuration section */ #define ANSI_PROTO /* This line would be added if the compiler has prototypes. Note that just using __STDC__ is not sufficient, as there are many compilers that have prototypes but do not define it. */ /* This stuff is buried somewhere deep in the include file, the person compiling our code does not look at it. */ #ifdef ANSI_PROTO #define FUNC(n,p) n p; #else #define FUNC(n,p) n (); #endif This is the code that makes use of the prototype macro. #include FUNC(int function, (int arg1, int arg2)) What happens is that, in the default file we ship, ANSI_PROTO is not specified and the FUNC macro will expand into something like extern int function(); And, since we use the right argument types, this will work on non-ANSI or ANSI compilers. If, however, the user *does* define ANSI_PROTO, the FUNC macro expands to extern int function(int arg1, int arg2)); and he gets the type checking benefits of the prototype. --- Bill novavax!proxftl!bill