From: Max Staudt <max@enpas.org>
To: Vincent Mailhol <vincent.mailhol@gmail.com>
Cc: Wolfgang Grandegger <wg@grandegger.com>,
Marc Kleine-Budde <mkl@pengutronix.de>,
linux-can@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Oliver Neukum <oneukum@suse.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6] can, tty: can327 CAN/ldisc driver for ELM327 based OBD-II adapters
Date: Sat, 14 May 2022 13:11:40 +0200 [thread overview]
Message-ID: <20220514131128.5e647fb8.max@enpas.org> (raw)
In-Reply-To: <CAMZ6RqLj2eLX2UWMvGc9rH2SP6HNuqBAXnwJ6q6qvk+7QWE8pA@mail.gmail.com>
On Sat, 14 May 2022 12:14:24 +0900
Vincent Mailhol <vincent.mailhol@gmail.com> wrote:
> But I still think it is possible to do pointer arithmetic.
>
> len = strnchr(elm->rxbuf, elm->rxfill, '\r') - elm->rxbuf;
> (I let you check that I did not do an off by one mistake).
>
> The above should also work with memchr(). Although the C standard
> doesn't allow pointer arithmetic on void *, GNU C adds an extension
> for that: https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html
>
> As I said before, your for loop is not fundamentally wrong, this is
> just not my prefered approach. You have my suggestion, choose what you
> prefer.
Yeah, this is the arithmetic that I'd like to avoid here. In my
opinion, it is clearer with indices.
If I were searching through a UTF-8 string (i.e. with variable width
chars), that'd be another matter entirely IMHO, and I'd rely on C
library functions that know more about UTF that I do. But it's really
just naked ASCII bytes this time.
...unless memchr() may be faster than the loop? Could this happen?
Max
next prev parent reply other threads:[~2022-05-14 11:11 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-12 18:29 [PATCH v6] can, tty: can327 CAN/ldisc driver for ELM327 based OBD-II adapters Max Staudt
2022-05-13 2:38 ` Vincent Mailhol
2022-05-13 6:31 ` Vincent Mailhol
2022-05-13 18:59 ` Max Staudt
2022-05-14 3:14 ` Vincent Mailhol
2022-05-14 11:11 ` Max Staudt [this message]
2022-05-14 12:24 ` Vincent Mailhol
2022-05-13 11:46 ` Marc Kleine-Budde
2022-05-13 11:52 ` Marc Kleine-Budde
2022-05-13 12:14 ` Vincent Mailhol
2022-05-14 11:04 ` Max Staudt
2022-05-14 12:10 ` Vincent Mailhol
2022-05-18 16:24 ` Vincent Mailhol
2022-05-18 16:31 ` Vincent Mailhol
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=20220514131128.5e647fb8.max@enpas.org \
--to=max@enpas.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=oneukum@suse.com \
--cc=vincent.mailhol@gmail.com \
--cc=wg@grandegger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.