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

Re: [PATCH] Fix compiler warning by properly initialize failed_errno

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 4, 2009, 19:09 UTC
Message-ID
<7v3a87o0pe.fsf@alter.siamese.dyndns.org>
In-Reply-To
<4A78834C.20002@kdbg.org>
Johannes Sixt <j6t@kdbg.org> writes:
Show 13 quoted lines
> Junio C Hamano schrieb:
>
>> We would want to be able to distinguish between a workaround for a
>> compiler that is not clever/careful enough, and a necessary
>> initialization.  In this particular case, it is the former, and we should
>> say
>>
>> 	int failed_errno = failed_errno;
>>
>> instead.
>
> Frankly, I prefer the initialization with 0; this is not a performance
> critical place and micro-optimization is not appropriate here.

It is not about optimization at all. This is about documenting the fact that we have audited and know that the use of this variable in the code that follows is Ok. Initializing to 0 gives a false impression that the code may rely on that value, but in this case nobody will ever read that zero before overwriting it with an assignment.

The compiler may optimize this out, but that is an insignificant (I agree this is not a performance critical codepath) side effect.

Previous: Johannes Sixt
Message 6 of 6 in “Fix compiler warning by properly initialize failed_errno”
  1. Fix compiler warning by properly initialize failed_errnoDavid Soria Parra, Aug 2, 2009
  2. Junio C HamanoAug 4, 2009
  3. sn_Aug 4, 2009
  4. Junio C HamanoAug 4, 2009
  5. Johannes SixtAug 4, 2009
  6. Junio C HamanoAug 4, 2009

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.