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

Re: [PATCH 3/4] ll-merge: initialize default_opts const

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 16, 2011, 07:49 UTC
Message-ID
<7vd3csqzgs.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CALkWK0mVxxq0345B_OJQwejpTBD=evOU_iAv39CvXv4mAi=09A@mail.gmail.com>
Ramkumar Ramachandra <artagnon@gmail.com> writes:
Show 13 quoted lines
> Hi Junio,
>
> Junio C Hamano wrote:
>> Ramkumar Ramachandra <artagnon@gmail.com> writes:
>>> [...]
>>> -     static const struct ll_merge_options default_opts;
>>> +     static const struct ll_merge_options default_opts = {0, 0, 0, 0};
>>
>> Doesn't "static" tell us that it will be in BSS, initialized to all zero
>> by definition?
>
> I'm uncertain about whether the C89 standard says this explicitly- icc
> is more pedantic than most mainstream compilers.

Actually I take a part of the comment back; as this is "static const", it is entirely plausible for a compiler to tell the linker to put it in rodata instead of bss, to cause any attempt to modify it to segv.

A datum that is implicitly initialized to all zero and not allowed to be modified might appear suspect to some compiler writers (especially when they are under influence ;-)), so I am not so surprised if a compiler issued a warning saying "did you forget to initialize it?".

Previous: Ramkumar RamachandraNext: Ramkumar Ramachandra
Message 7 of 9 in “Fix minor warnings reported by icc”
  1. 0/4 Fix minor warnings reported by iccRamkumar Ramachandra, Nov 15, 2011
  2. 1/4 http: remove unused function hex()Ramkumar Ramachandra, Nov 15, 2011
  3. 2/4 convert: don't mix enum with intRamkumar Ramachandra, Nov 15, 2011
  4. 3/4 ll-merge: initialize default_opts constRamkumar Ramachandra, Nov 15, 2011
  5. Junio C HamanoNov 15, 2011
  6. Ramkumar RamachandraNov 16, 2011
  7. Junio C HamanoNov 16, 2011
  8. 4/4 sha1_file: don't mix enum with intRamkumar Ramachandra, Nov 15, 2011
  9. 5/4 git-compat-util: don't assume value for undefined variableRamkumar Ramachandra, Nov 15, 2011

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.