ANSI C prototypes

John Stanley stanley at phoenix.com
Wed Oct 31 05:32:46 AEST 1990


ptf at cs.bham.ac.uk (Paul Flinders <FlindersPT>) writes:

> Can anbody suggest an elegant solution to the following. 
> 
> in foo.h:
> 	extern void ddprintf(const char *fmt, ...);
> 
> BUT in foo.c:
> 
> 	void ddprintf(va_alist)
> 	va_dcl;
> 
> this causes problems. The only solution that I've thought of is to
> define some preprocessor token in foo.c _before_ the include of foo.h
> and then #ifdef the extern declaration out. This seems a little messy
> though. Anybody else have any solutions to this.

There are two simple solutions:

   1) Use a VAX. VMS C does not (at least, did not) care about the extern
missing from extern declarations. This means the same include that
defines a global int i may be included in all files. The linker on VMS
happily ignores multiple definitions and layers everything with the same
name to the same address.

   2) Do what you thought of. It is pretty common, in my experience, that
the main routine has a #define MAIN, with the included files having:

	#ifndef MAIN
	#define EXTERN
	#else
	#define EXTERN extern
	#endif

This way, all global variables get defined in the main routine, and
declared in the rest.  You probably could just #define extern to nothing,
but that would screw up any externs in any files follwing that one.



"Arinth is a beautiful planet." "Oh, have you been there?"
  "Yes, but not yet." The Doctor. (TB)



More information about the Comp.lang.c mailing list