mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Schindelin <>
To: Junio C Hamano <>
Cc: Johannes Schindelin via GitGitGadget <>,
Subject: Re: [PATCH 1/2] pkt-line: fix declaration of `set_packet_header()`
Date: Tue, 14 May 2019 14:57:01 +0200 (CEST)	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

Hi Junio,

On Tue, 14 May 2019, Junio C Hamano wrote:

> "Johannes Schindelin via GitGitGadget" <>
> writes:
> > From: Johannes Schindelin <>
> >
> > When this function was changed in a97d00799a19 (remote-curl: use
> > post_rpc() for protocol v2 also, 2019-02-21) from file-local to global,
> > the declaration was incorrectly missing the `const` qualifier.
> I do not quite get it.  Back when the function was file-scope
> static, it did not even have a separate declaration, and the
> definition the said commit added looks correct to me.

Right, I should have said "the new declaration" instead of "the

> Having "const int size" parameter in the definition of a function
> does help the compilers and the developers by making sure any
> earlier reference to the parameter in the function would not modify
> it and cause later reference to obtain a different value.
> But the parameter treated as a constant without getting modified
> during the invocation of the function is an implementation detail of
> the function; there is no point exposing that implementation detail
> to its callers.  It does not even help the compilers handling the
> caller's compilation unit---the parameter is passed by value, so the
> caller knows that the callee would not modify it without "const"
> there.
> Does the language even allow flagging "const int in the definition,
> int in the declaration" as a warning-worthy discrepancy?

Apparently it does, as MS Visual C does issue a warning (and with `/Wall`,
it fails).

In any case, I don't think that it makes sense to have a function
declaration whose signature differs from the definition's.


> > -void set_packet_header(char *buf, int size);
> > +void set_packet_header(char *buf, const int size);

  reply	other threads:[~2019-05-14 12:57 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 [this message]
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
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:

  List information:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \

* 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

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