From: David Laight <david.laight.linux@gmail.com>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Markus Elfring <Markus.Elfring@web.de>,
Dmitry Baryshkov <dmitry.baryshkov@linaro.org>,
kernel-janitors@vger.kernel.org, freedreno@lists.freedesktop.org,
dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org,
Abhinav Kumar <quic_abhinavk@quicinc.com>,
Archit Taneja <architt@codeaurora.org>,
Daniel Vetter <daniel@ffwll.ch>, David Airlie <airlied@gmail.com>,
Jeykumar Sankaran <jsanka@codeaurora.org>,
Jordan Crouse <jordan@cosmicpenguin.net>,
Marijn Suijten <marijn.suijten@somainline.org>,
Rob Clark <robdclark@gmail.com>, Sean Paul <sean@poorly.run>,
Simona Vetter <simona@ffwll.ch>, Vinod Koul <vkoul@kernel.org>,
cocci@inria.fr, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [RFC] Clarification for “undefined behaviour”?
Date: Wed, 5 Mar 2025 21:35:01 +0000 [thread overview]
Message-ID: <20250305213501.496ea4bf@pumpkin> (raw)
In-Reply-To: <ed9e65a7-6cdf-4d93-83a8-464b47a4bc1d@stanley.mountain>
On Wed, 5 Mar 2025 17:30:28 +0300
Dan Carpenter <dan.carpenter@linaro.org> wrote:
> On Wed, Mar 05, 2025 at 02:17:32PM +0000, David Laight wrote:
...
> > And the 'fun' starts because NULL isn't required to use the all-zero
> > bit pattern.
> > Regardless of the bit-pattern, things like (void *)(1 - 1) are valid
> > NULL pointers.
> >
> > Of course, while C allows this, I doubt NULL has ever been other than 0.
> > (It was 0 on a system I used many years ago where the O/S invalid pointer
> > was ~0.)
>
> Kernel style guidelines don't even allow if (p == NULL) so we would be
> screwed. :P
Doesn't matter:
if (!p) ...
if (p == 0) ...
if (p == (void *)0) ...
if (p == NULL) ...
if (p == (void *)(constant integer expression with value 0)) ...
and the equivalent assignments all behave the same regardless of the
bit-pattern use for NULL.
So:
union { long l; void *p; } lpu;
lpu.p = 0;
return lpu.l;
Returns ABI (implementation) defined constant value.
I think the only requirement is that it can never be the address
of a valid variable.
David
prev parent reply other threads:[~2025-03-05 21:35 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <40c60719-4bfe-b1a4-ead7-724b84637f55@web.de>
[not found] ` <1a11455f-ab57-dce0-1677-6beb8492a257@web.de>
[not found] ` <13566308-9a80-e4aa-f64e-978c02b1406d@web.de>
2023-04-11 16:43 ` [PATCH] drm/msm/dpu: Delete a variable initialisation before a null pointer check in two functions Dmitry Baryshkov
2023-04-11 16:44 ` Abhinav Kumar
2025-03-02 20:56 ` [PATCH RESEND] " Markus Elfring
2025-03-02 23:01 ` Dmitry Baryshkov
2025-03-03 7:14 ` Dan Carpenter
2025-03-03 8:15 ` [RESEND] " Markus Elfring
2025-03-03 8:24 ` Dan Carpenter
2025-03-05 8:40 ` [RFC] Clarification for “undefined behaviour”? Markus Elfring
2025-03-05 8:51 ` Dan Carpenter
2025-03-05 9:20 ` Markus Elfring
2025-03-05 14:17 ` David Laight
2025-03-05 14:30 ` Dan Carpenter
2025-03-05 21:35 ` David Laight [this message]
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=20250305213501.496ea4bf@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=Markus.Elfring@web.de \
--cc=airlied@gmail.com \
--cc=architt@codeaurora.org \
--cc=cocci@inria.fr \
--cc=dan.carpenter@linaro.org \
--cc=daniel@ffwll.ch \
--cc=dmitry.baryshkov@linaro.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=freedreno@lists.freedesktop.org \
--cc=jordan@cosmicpenguin.net \
--cc=jsanka@codeaurora.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marijn.suijten@somainline.org \
--cc=quic_abhinavk@quicinc.com \
--cc=robdclark@gmail.com \
--cc=sean@poorly.run \
--cc=simona@ffwll.ch \
--cc=vkoul@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