

extern                      C Keyword                      extern




Declare storage class


extern indicates that a C element belongs to the _e_x_t_e_r_n_a_l storage
class.  Both  variables and functions  may be declared  to be ex-
tern.  Use of this keyword tells the C compiler that the variable
or  function is  defined outside  of the  present file  of source
code.  All  functions and variables defined  outside of functions
are implicitly extern unless declared static.

When a  source file references  data that are  defined in another
file, it must  declare the data to be extern,  or the linker will
return an error message of the form:


        undefined symbol _n_a_m_e


For example, the following declares the array tzname:


        extern char tzname[2][32];


When  a function  calls  a function  that is  defined in  another
source file or in a library, it should declare the function to be
extern.  In  the absence of  a declaration, extern  functions are
assumed to  return ints, which may cause  serious problems if the
function actually returns a  32-bit pointer (such as on the 68000
or i8086 LARGE model), a long, or a double.

For example, the function mmaalllloocc appears in a library and returns
a pointer; therefore, it should be declared as follows:


        extern char *malloc();


If you do not do so,  the compiler assumes that mmaalllloocc returns an
iinntt, and generate the error message


        integer pointer pun


when you attempt to use mmaalllloocc in your program.

***** See Also *****

auto, C keywords, pun, register, static, storage class






COHERENT Lexicon                                           Page 1


