Re: Pointer subtraction with a null pointer

From: Isaac Morland <isaac(dot)morland(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Subject: Re: Pointer subtraction with a null pointer
Date: 2022-03-26 16:34:10
Message-ID: CAMsGm5ck5rfhE=MU+frgdEfUL8pHZBkkP=bBHXuHZzDXTcF_2w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, 26 Mar 2022 at 12:24, Andres Freund <andres(at)anarazel(dot)de> wrote:

> NULL can never be part of the same "array object" or one past past the last
> element as the pointer it is subtracted from. Hence the undefined beaviour.
>

Even more fundamentally, NULL is not 0 in any ordinary mathematical sense,
even though it can be written 0 in source code and is often (but not
always) represented in memory as an all-0s bit pattern. I'm not at all
surprised to learn that arithmetic involving NULL is undefined.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2022-03-26 16:34:41 Re: Pointer subtraction with a null pointer
Previous Message Andres Freund 2022-03-26 16:24:18 Re: Pointer subtraction with a null pointer