Mail Archives: djgpp/1994/04/02/10:28:11
Wonkoo Kim wrote:
> One thing that I'm still wondering is, why include\*.h in gcc or bcc do not
> have 'extern' specifier for function protocols, but C books[K&R] say that
> 'extern' is required if it is external. Is there some difference between
> builtin *.h and user written *.h? Or, just omitted 'extern' from
> include\*.h because of implicit extern capability of the compiler/linker
> when a function is external to a module but included .h has the non-extern
> function protocol?
Because funtion prototypes are not the same as variable declarations.
A function prototype of the form "<return_type> f_name(args...);" is
just like declaring a variable "extern;" it means that the function
is going to be defined elsewhere, and it's an error if it isn't (a
link-time error, that is). Explicitly declaring a function "extern"
isn't necessary; functions can only be "extern" or "static."
Obviously, you can't actually *define* a function (that is, provide
the actual body of its code) more than once. But prototypes don't do
that; they just tell the compiler how to handle invocations of that
function (i.e. how to push arguments onto the stack).
Are you reading the original K&R, or the second edition? The rules
have changed a bit for the ANSI spec (mostly for the better, IMHO). I
can't find a place where K&R2 says anything about "extern" for function
prototypes. For that matter, I've never seen a piece of code that ever
declared a function "extern" explicitly....
Obligatory soapbox: always use new-style function prototypes. In
fact, if you're writing in C, use the -ansi switch habitually. It'll
get you into some good habits. :-)
---------------------------------------------------------------------
Christopher Tate | "Blue ice cubes? How degenerate!"
MSD, Inc. |
fixer AT faxcsl DOT dcrt DOT nih DOT gov | < anybody recognize the source? >
- Raw text -