From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: Jeff King <peff@peff.net>,
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>,
git@vger.kernel.org
Subject: Re: [PATCH 1/2] pkt-line: fix declaration of `set_packet_header()`
Date: Wed, 15 May 2019 12:39:04 +0200 (DST) [thread overview]
Message-ID: <nycvar.QRO.7.76.6.1905151234370.44@tvgsbejvaqbjf.bet> (raw)
In-Reply-To: <xmqqa7fo8pdg.fsf@gitster-ct.c.googlers.com>
Hi Junio,
On Wed, 15 May 2019, Junio C Hamano wrote:
> 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:
> -- >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
> 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";
>
>
next prev parent reply other threads:[~2019-05-15 10:39 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-13 22:43 [PATCH 0/2] pkt-line: fix incorrect function declaration Johannes Schindelin via GitGitGadget
2019-05-13 22:43 ` [PATCH 1/2] pkt-line: fix declaration of `set_packet_header()` Johannes Schindelin via GitGitGadget
2019-05-13 23:24 ` Junio C Hamano
2019-05-14 12:57 ` Johannes Schindelin
2019-05-14 14:43 ` Jeff King
2019-05-14 14:44 ` Jeff King
2019-05-15 1:42 ` Junio C Hamano
2019-05-15 1:44 ` Jeff King
2019-05-15 10:39 ` Johannes Schindelin [this message]
2019-05-16 2:24 ` Junio C Hamano
2019-05-16 3:42 ` Jeff King
2019-05-16 4:28 ` Junio C Hamano
2019-05-17 18:54 ` Johannes Schindelin
2019-05-13 22:43 ` [PATCH 2/2] parse-options: adjust `parse_opt_unknown_cb()`s declared return type Johannes Schindelin via GitGitGadget
2019-05-13 23:29 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=nycvar.QRO.7.76.6.1905151234370.44@tvgsbejvaqbjf.bet \
--to=johannes.schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).