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

Re: [PATCH 1/2] pkt-line: fix declaration of `set_packet_header()`

From
Junio C Hamano <gitster@pobox.com>
Date
May 16, 2019, 02:24 UTC
Message-ID
<xmqq36lf5e7a.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<nycvar.QRO.7.76.6.1905151234370.44@tvgsbejvaqbjf.bet>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 5 quoted lines
>> lacked the "const" for that reason, but apparently some compilers
>> complain about the parameter type mismatch.
>
> We could be more explicit, as we know exactly that it is MS Visual C 2017
> that is complaining.

We could be, but I do not see a point of shaming one particular compiler vendor.

Show 5 quoted lines
>> Let's squelch it by removing the "const" that is pointless for a
>> small function like this, which would not help optimizing compilers
>
> It is not pointless because of the size of the function, but because `int`
> is already a type that is always passed by value, never by reference.

You are looking only at the prototype side (i.e. declaration in *.h). Yes it is pointless for the callers. For the callee, the story is different and pass-by-value does not even get in the picture.

The mention of pointless-ness I made was about the implementation side (i.e. definition in *.c). For a sufficiently large and complex function implementation, being able to say upfront that this incoming parameter is never modified would help following the logic in the implementation, so "const int param" in the parameter list of a definition is *not* pointless in general. But apparently some compilers are not happy abot "const int param" in implementation that is paired with "int param" in prototype, we are dropping a const that could be useful, with an excuse that for this particular function that is small and trivial, we can live without.

Previous: Johannes SchindelinNext: Jeff King
Message 10 of 15 in “pkt-line: fix incorrect function declaration”
  1. 0/2 pkt-line: fix incorrect function declarationJohannes Schindelin via GitGitGadget, May 13, 2019
  2. 1/2 pkt-line: fix declaration of `set_packet_header()`Johannes Schindelin via GitGitGadget, May 13, 2019
  3. Junio C HamanoMay 13, 2019
  4. Johannes SchindelinMay 14, 2019
  5. Jeff KingMay 14, 2019
  6. Jeff KingMay 14, 2019
  7. Junio C HamanoMay 15, 2019
  8. Jeff KingMay 15, 2019
  9. Johannes SchindelinMay 15, 2019
  10. Junio C HamanoMay 16, 2019
  11. Jeff KingMay 16, 2019
  12. Junio C HamanoMay 16, 2019
  13. Johannes SchindelinMay 17, 2019
  14. 2/2 parse-options: adjust `parse_opt_unknown_cb()`s declared return typeJohannes Schindelin via GitGitGadget, May 13, 2019
  15. Junio C HamanoMay 13, 2019

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.