From: Walter Harms <wharms@bfs.de>
To: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>,
Alejandro Colomar <colomar.6.4.3@gmail.com>
Cc: "linux-man@vger.kernel.org" <linux-man@vger.kernel.org>
Subject: AW: [PATCH v2] tsearch.3: Simplify type usage and remove unneeded casts
Date: Mon, 7 Sep 2020 07:54:28 +0000 [thread overview]
Message-ID: <16456ba5979244e0981c3764fd564c49@bfs.de> (raw)
In-Reply-To: <c27b577c-b8b6-4267-78f4-eba030a8ea48@gmail.com>
Hello,
i am sorry to interrupt here but ...
IMHO the void *val is here for a reason, because it means
"this can be anything" the reason why int ** works here is
that the example uses int. You make the example to specific
in this case. may be the example from bsearch is better here.
________________________________________
Von: linux-man-owner@vger.kernel.org [linux-man-owner@vger.kernel.org] im Auftrag von Michael Kerrisk (man-pages) [mtk.manpages@gmail.com]
Gesendet: Samstag, 5. September 2020 21:42
An: Alejandro Colomar
Cc: mtk.manpages@gmail.com; linux-man@vger.kernel.org
Betreff: Re: [PATCH v2] tsearch.3: Simplify type usage and remove unneeded casts
Hello Alex,
On 9/5/20 6:10 PM, Alejandro Colomar wrote:
> The type of `val` is `int **`, and it will work with tsearch()
> anyway because of implicit cast from `void *`, so declaring it as an
> `int **` simplifies the code.
Thanks, patch applied.
Cheers,
Michael
> Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
> ---
> man3/tsearch.3 | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/man3/tsearch.3 b/man3/tsearch.3
> index 2e8403130..7b82d9bd3 100644
> --- a/man3/tsearch.3
> +++ b/man3/tsearch.3
> @@ -323,7 +323,7 @@ action(const void *nodep, VISIT which, int depth)
> int
> main(void)
> {
> - void *val;
> + int **val;
>
> srand(time(NULL));
> for (int i = 0; i < 12; i++) {
> @@ -332,7 +332,7 @@ main(void)
> val = tsearch((void *) ptr, &root, compare);
> if (val == NULL)
> exit(EXIT_FAILURE);
> - else if ((*(int **) val) != ptr)
> + else if (*val != ptr)
> free(ptr);
> }
> twalk(root, action);
>
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
next prev parent reply other threads:[~2020-09-07 7:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-05 10:50 [PATCH] tsearch.3: Simplify type usage and remove unneeded casts Alejandro Colomar
2020-09-05 15:35 ` Michael Kerrisk (man-pages)
2020-09-05 15:41 ` Alejandro Colomar
2020-09-05 16:10 ` [PATCH v2] " Alejandro Colomar
2020-09-05 19:42 ` Michael Kerrisk (man-pages)
2020-09-07 7:54 ` Walter Harms [this message]
2020-09-08 8:30 ` AW: " Alejandro Colomar
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=16456ba5979244e0981c3764fd564c49@bfs.de \
--to=wharms@bfs.de \
--cc=colomar.6.4.3@gmail.com \
--cc=linux-man@vger.kernel.org \
--cc=mtk.manpages@gmail.com \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox