declarations in include files: how do YOU feel?

Doug Gwyn gwyn at smoke.BRL.MIL
Fri May 12 07:34:20 AEST 1989


In article <179 at larry.sal.wisc.edu> jwp at larry.sal.wisc.edu (Jeffrey W Percival) writes:
>The situation is, suppose I have a bunch of routines that are packaged
>into a lib.a, and there is an associated include file "lib.h" that
>users need to include.  Should the lib.h file contain extern declarations
>for everything in lib.a, or not?

If the library is naturally divisible into smaller packages (e.g. array
operations, error reporting, ...) then provide a separate header for
each "package" that defines/declares things for just that package.
Otherwise, define/declare them all in lib.h.  If functions in lib.a
can call other functions in lib.a, the user has to be aware of the
total set of external names defined by the library anyway so that he
doesn't accidentally usurp one for his application.  (That would break
functions that called that usurped function.)

Just because a header includes a declaration of a function does not mean
that the function will be linked into the executable image; only if it
(or some other external defined in the same object module) is referred
to will the corresponding object module be linked in.  (There are some
linkers that violate this model, but it's pretty near universally agreed
that they're broken.)



More information about the Comp.lang.c mailing list