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
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
May 15, 2019, 10:39 UTC
Message-ID
<nycvar.QRO.7.76.6.1905151234370.44@tvgsbejvaqbjf.bet>
In-Reply-To
<xmqqa7fo8pdg.fsf@gitster-ct.c.googlers.com>
Hi Junio,
On Wed, 15 May 2019, Junio C Hamano wrote:
Show 9 quoted lines
> Jeff King <peff@peff.net> writes:
>
> > I do have a slight preference for going the _other_ way. There is no
> > need to mark the parameter as const in the definition. It is passed by
> > value, so nobody except the function body cares either way. And we have
> > many function bodies where value-passed parameters (or local variables!)
> > are not marked as const, even though they are only assigned to once.
>
> That would be more like this patch, then?
I can live very well with this patch.
Just two minor comments:
Show 8 quoted lines
> -- >8 --
> Subject: pkt-line: drop 'const'-ness of a param to set_packet_header()
>
> The fact that the incoming parameter is used as read-only in the
> fuction is an implementation detail that the callers should not have
> to know, and the prototype defined for the function in pkt-line.h
> 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.

> 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.

If at all, it would make a difference if the function was inlined, so I would argue that it would be pointless for large functions.

But both aspects are moot and more philosophical than anything else in this context.

Thanks, Dscho

Show 23 quoted lines
> nor reading humans that much.
>
> Noticed-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> Helped-by: Jeff King <peff@peff.net>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>  pkt-line.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/pkt-line.c b/pkt-line.c
> index c9ed780d0b..a0e87b1e81 100644
> --- a/pkt-line.c
> +++ b/pkt-line.c
> @@ -119,7 +119,7 @@ void packet_buf_delim(struct strbuf *buf)
>  	strbuf_add(buf, "0001", 4);
>  }
>
> -void set_packet_header(char *buf, const int size)
> +void set_packet_header(char *buf, int size)
>  {
>  	static char hexchar[] = "0123456789abcdef";
>
>
Previous: Jeff KingNext: Junio C Hamano
Message 9 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.