Proper use of "extern" ...

Alastair Adamson alastair at axis.UUCP
Tue Jun 10 01:56:06 AEST 1986


[feed this line to the Orcs]
In article <223 at comp.lancs.ac.uk> david at comp.lancs.ac.uk (David Coffield) writes:
>Suggestions, please, as to the correct use of "extern" ..
>At the top of this file do we put
>a) static void g() 	or
>b) extern void g()?	(extern static must be meaningless).

I would always prefer a) since it helps the reader by making explicit
the fact that the function is local to this file. Further, I like to
declare all extern (other file, library) functions and static functions
before the definition of the first function in a file, after any #includes,
#defines and global variables, as in:

	#include	lines
	#define		lines
	global variables (definitions)
	extern globals   (declarations)
	static functions (declarations)
	extern functions (declarations)
	function definitions

Thus, I would also have said "static void f()" before f()'s definition.

There is a problem with static functions, namely that some C compilers
don't know how to handle them and generate illegal instructions so
that the assembler stage bombs out. You may say that one should avoid
such ridiculous compilers and I would agree with you. Unfortunately,
however, when porting software to other computers one has to put up
with what's available!



More information about the Comp.lang.c mailing list