Re: Remove useless casting to the same type

From: Jacob Champion <jacob(dot)champion(at)enterprisedb(dot)com>
To: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Remove useless casting to the same type
Date: 2025-12-01 17:50:43
Message-ID: CAOYmi+nDUxtgZihMAUX+tTh23OBVd0MUqE+M85kiT9istVbOmw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Nov 24, 2025 at 9:46 PM Bertrand Drouvot
<bertranddrouvot(dot)pg(at)gmail(dot)com> wrote:
> I think that even with the cast in place, it's good to check the type of data.
> Not for the line that follows (i.e: "data += sizeof(uint32) * 2") but to check
> that the cast makes sense and does not hide "wrong" pointer manipulation.

From a specifier standpoint ("accidentally got rid of const"), yes.
From a pointer math standpoint, `(char *) ptr + offset` has a specific
meaning to me, and I was arguing that hiding that meaning isn't
necessarily useful in all cases.

But! Peter's followup makes this moot. Which is good, and it might
serve as its own blueprint for when we next see a situation like this.

> Yeah, "*(s->str + pos)" is already used in SetAt() and also in IsVowel(). Instead
> of changing those 3, I'd prefer to keep the current change and keep the patch
> focus on its intend. We could change those in a dedicated patch afterward if we
> feel the need.

Fine by me. Thanks for this cleanup work!

--Jacob

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jacob Champion 2025-12-01 17:51:19 Re: Remove useless casting to the same type
Previous Message Nathan Bossart 2025-12-01 17:25:13 split tablecmds.c