Re: get rid of Pointer type, mostly

Поиск
Список
Период
Сортировка
От Robert Haas
Тема Re: get rid of Pointer type, mostly
Дата
Msg-id CA+TgmobhKe5WJybZ0EGQ85Qkxr-KLx4uW2_hFqt0iPbYq-af7Q@mail.gmail.com
обсуждение исходный текст
Ответ на Re: get rid of Pointer type, mostly  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: get rid of Pointer type, mostly
Список pgsql-hackers
On Mon, Nov 24, 2025 at 11:33 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> We have lots of places where we use trivial typedefs to annotate
> what something is.  For instance "text *" is not really different
> from "struct varlena *", but I don't think anyone would be in favor
> of removing the "text" typedef.  In this case we have decades of
> practice using Pointer to annotate something as being a generic
> pointer.

In my mind, a text * points to a varlena whose payload data is valid
in the relevant encoding, i.e. something that will be legal if you
pass it to functions that expect to work on text Datums. But I'm not
very clear on what Pointer is supposed to mean. Sometimes we use it to
indicate that a char * is a generic pointer rather than a pointer to a
C string, but sometimes we just write char * anyway, so you can't use
the fact that something is declared as char * to mean that it isn't
intended as a generic pointer. If we change Pointer to be void *, then
even that clarifying value is lost, since void * has no other meaning.
But if it were up to me, I'd rip out Pointer completely, because
reading code that uses the native C type names is easier for me than
reading code that substitutes other notation.

In my experience, there's rarely any practical confusion about whether
char * is a C string, a character array, or a generic pointer. It's
not impossible for such confusion to exist, of course, but typically
pointer arithmetic is confined to relatively brief stretches of code
to avoid breaking the author's brain, or the reader's. If you see a
pointer to a struct get cast to a char * or the other way around, you
know what's happening. It would be confusing if the char * intended as
a generic pointer were passed through multiple layers of function
calls, but for those cases it's typically convenient to use void *, so
the problem doesn't really arise, and in the rare cases where it
might, one can always write a comment to clear things up.

We have lots of data types that seem to me to have enough
documentation value to justify their existence, but IMHO, this isn't
one of them.

--
Robert Haas
EDB: http://www.enterprisedb.com



В списке pgsql-hackers по дате отправления: