Subject: Re: C lesson
To: None <port-mac68k@NetBSD.ORG>
From: Brian J. Johnson <johnsons@wwa.com>
List: port-mac68k
Date: 03/07/1996 13:32:03
Markus Hitter writes:
> Maybe I have slept in one of the programming lessons but I can't imagine what
> this 'extern' in front of the function definition does. If I don't comment it
> out this routine is left as a unreferenced symbol. I copied this example from
> ncr5380.c.
> 
> extern __inline__ int wait_req_true(void)
> {
>         int     timeout = 25000;
> 
>         while ...
> 
> Perhaps someone can help me make my brain working better?

The explanation was less than obvious to me, so I looked it up.
Here's what the "Inline" topic on the GCC info page has to say:

     If you specify both `inline' and `extern' in the function
  definition, then the definition is used only for inlining.  In no case
  is the function compiled on its own, not even if you refer to its
  address explicitly.  Such an address becomes an external reference, as
  if you had only declared the function, and had not defined it.

     This combination of `inline' and `extern' has almost the effect of a
  macro.  The way to use it is to put a function definition in a header
  file with these keywords, and put another copy of the definition
  (lacking `inline' and `extern') in a library file.  The definition in
  the header file will cause most calls to the function to be inlined.
  If any uses of the function remain, they will refer to the single copy
  in the library.

So if you're using GCC, it sounds like the above code fragment should
be in a header file, not a .c file, and that the version in the .c
file should not mention "extern".  Other compilers may handle this
case differently, of course (whether they _should_ or not is another
discussion....)

						Brian