Re: Remove useless casting to the same type - Mailing list pgsql-hackers

From Jacob Champion
Subject Re: Remove useless casting to the same type
Date
Msg-id CAOYmi+nDUxtgZihMAUX+tTh23OBVd0MUqE+M85kiT9istVbOmw@mail.gmail.com
Whole thread Raw
In response to Re: Remove useless casting to the same type  (Bertrand Drouvot <bertranddrouvot.pg@gmail.com>)
List pgsql-hackers
On Mon, Nov 24, 2025 at 9:46 PM Bertrand Drouvot
<bertranddrouvot.pg@gmail.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



pgsql-hackers by date:

Previous
From: Nathan Bossart
Date:
Subject: split tablecmds.c
Next
From: Jacob Champion
Date:
Subject: Re: Remove useless casting to the same type