From: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
To: Alejandro Colomar <colomar.6.4.3@gmail.com>
Cc: mtk.manpages@gmail.com, linux-man@vger.kernel.org
Subject: Re: [PATCH] tsearch.3: Simplify type usage and remove unneeded casts
Date: Sat, 5 Sep 2020 17:35:28 +0200 [thread overview]
Message-ID: <7f2cfb54-1994-5bc7-d885-0d60cd615c81@gmail.com> (raw)
In-Reply-To: <20200905105024.163147-1-colomar.6.4.3@gmail.com>
Hi Alex,
On 9/5/20 12:50 PM, Alejandro Colomar wrote:
> The type of `var` is `int **`, and it will work with tsearch()
> anyway because of implicit cast from `void *`, so declaring it as an
> `int **` simplifies the code.
>
> Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
> ---
> man3/tsearch.3 | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
By chance, I've just made a conflicting change, but also...
> diff --git a/man3/tsearch.3 b/man3/tsearch.3
> index 32ddb8127..65fcadc52 100644
> --- a/man3/tsearch.3
> +++ b/man3/tsearch.3
> @@ -323,8 +323,7 @@ action(const void *nodep, VISIT which, int depth)
> int
> main(void)
> {
> - int i, *ptr;
> - void *val;
> + int i, *ptr, **val;
Not quite your fault, since you followed an already poor example,
but many people (and I am one of them) frown on declarations lines
such as the above: 'int', 'int *' and 'int **' are three different
types, and it's considered bad form to declare variables with
different type in one source line. (It's very easy to overlook
an asterisk or two when scanning the source.) Better is:
int i
int *ptr;
int **val;
>
> srand(time(NULL));
> for (i = 0; i < 12; i++) {
> @@ -333,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);
Could you please recraft this patch against current Git, which
changed in the last minutes...
Thanks,
Michael
--
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-05 15:35 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) [this message]
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 ` AW: " Walter Harms
2020-09-08 8:30 ` 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=7f2cfb54-1994-5bc7-d885-0d60cd615c81@gmail.com \
--to=mtk.manpages@gmail.com \
--cc=colomar.6.4.3@gmail.com \
--cc=linux-man@vger.kernel.org \
/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