git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] CodingGuidelines: mention "static" and "extern"

From
Stefan Beller <sbeller@google.com>
Date
Feb 8, 2018, 21:43 UTC
Message-ID
<CAGZ79kYjHMYO19bJUQNWXyiwOp3HwiiAYuOHO9O7VnxUzzC1Tg@mail.gmail.com>
In-Reply-To
<20180208213806.GA6381@sigill.intra.peff.net>
On Thu, Feb 8, 2018 at 1:38 PM, Jeff King <peff@peff.net> wrote:
Show 44 quoted lines
> On Thu, Feb 08, 2018 at 01:04:08PM -0800, Stefan Beller wrote:
>
>> You may sense a pattern here: I currently have the very firm understanding
>> we use the extern keyword in our codebase.
>>
>> And I can also attest that this was not always the case, as back in the
>> day I remember writing patches without the extern keyword only to be told:
>> (A) be similar to the function in the next lines
>> (B) the standard is to use extern
>> and I was convinced it was a bad decision to prefix declarations with
>> the extern keyword, but followed along as I don't want to have style
>> in the way of writing features.
>
> It definitely was the case that people used to suggest "extern". I think
> this was a Linus-ism from the early days, and I have been hating it for
> almost 12 years now. ;)
>
>>   $ cat Documentation/CodingGuidelines |grep extern
>>   $ # oh no it's empty!
>>
>> Care to add a section to our coding guidelines?
>
> Here's a patch.
>
> -- >8 --
> Subject: [PATCH] CodingGuidelines: mention "static" and "extern"
>
> It perhaps goes without saying that file-local stuff should
> be marked static, but it does not hurt to remind people.
>
> Less obvious is that we are settling on "do not include
> extern in function declarations". It is already the default
> unless the function was previously declared static (but if
> you are following a static declaration with an unmarked one,
> you should think about why you are declaring the thing
> twice). And so it just becomes an extra noise-word in our
> header files.
>
> We used to give the opposite advice, so there are quite a
> few "extern" markers in early Git code. But this at least
> makes a concrete suggestion that we can follow going
> forward.
>
> Signed-off-by: Jeff King <peff@peff.net>
Reviewed-by: Stefan Beller <sbeller@google.com>

... and now I can resend that patch, after fixing it to follow our style. :)

Show 23 quoted lines
> ---
>  Documentation/CodingGuidelines | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
> index c4cb5ff0d4..48aa4edfbd 100644
> --- a/Documentation/CodingGuidelines
> +++ b/Documentation/CodingGuidelines
> @@ -386,6 +386,11 @@ For C programs:
>   - Use Git's gettext wrappers to make the user interface
>     translatable. See "Marking strings for translation" in po/README.
>
> + - Variables and functions local to a given source file should be marked
> +   with "static". Variables that are visible to other source files
> +   must be declared with "extern" in header files. However, function
> +   declarations should not use "extern", as that is already the default.
> +
>  For Perl programs:
>
>   - Most of the C guidelines above apply.
> --
> 2.16.1.365.g89f5777adf
>
Previous: Jeff KingNext: Eric Sunshine
Message 5 of 16 in “color.h: document and modernize header”
  1. color.h: document and modernize headerStefan Beller, Feb 8, 2018
  2. Jeff KingFeb 8, 2018
  3. Stefan BellerFeb 8, 2018
  4. CodingGuidelines: mention "static" and "extern"Jeff King, Feb 8, 2018
  5. Stefan BellerFeb 8, 2018
  6. Eric SunshineFeb 8, 2018
  7. Jonathan TanFeb 9, 2018
  8. Jeff KingFeb 9, 2018
  9. Eric SunshineFeb 8, 2018
  10. Jeff KingFeb 8, 2018
  11. color.h: document and modernize headerStefan Beller, Feb 12, 2018
  12. Eric SunshineFeb 12, 2018
  13. color.h: document and modernize headerStefan Beller, Feb 13, 2018
  14. Eric SunshineFeb 13, 2018
  15. Eric SunshineFeb 14, 2018
  16. Stefan BellerFeb 14, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.