where do you put prototype declarations?

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Jan 28 13:52:54 AEST 1989


In article <584 at mccc.UUCP> pjh at mccc.UUCP (Pete Holsberg) writes:
>Does it make a significant difference?  If so, what is it?  Thanks.

Not really; the external declarations remain in scope until the
end of the translation unit and the internal ones go out of scope
at the end of the block within which they're declared.  For extern
functions and data, there cannot be conflicting definitions anyway,
so one might as well use file scope for their declarations.  The
only practical uses I can think of for hiding declarations of
externs outside a block would generally be considered poor style.

There are languages that require explicit "importing" of identifiers
in order to use them in a block.  Programmers who think along those
lines may well prefer to write their C code like that.  Personally,
I prefer to finish the job of declaring externs just after the
#includes that started the job near the start of the source file.
It also usually saves on keystrokes (or mouse clicks, for "sam"
users) since only one declaration is needed for each extern that way.



More information about the Comp.lang.c mailing list