Re: Safer hash table initialization macro - Mailing list pgsql-hackers

From Jelte Fennema-Nio
Subject Re: Safer hash table initialization macro
Date
Msg-id CAGECzQSnhom3wFnY6a7xepGfxzzVmwyNCcJQE=y8UYS-g2G=RQ@mail.gmail.com
Whole thread Raw
In response to Re: Safer hash table initialization macro  (Thomas Munro <thomas.munro@gmail.com>)
Responses Re: Safer hash table initialization macro
List pgsql-hackers
On Fri, 5 Dec 2025 at 02:30, Thomas Munro <thomas.munro@gmail.com> wrote:
> How much of our header stuff is supposed to work from C++ too?

I think it's nice if it works, but it doesn't seem the most important.
Especially since C++ has its own hashmaps. And if it really needs to
create a hashmap it's still possible to call the.

> I suppose you could
> write the typeof-based version you already hinted at, but only use it
> for __cplusplus__ (where typeof exists as decltype).

I tried to figure something out that would work in C++ (with help of
Claude), but I wasn't able to create a version of the macros without
also needing to add:

#ifdef __cplusplus
}
#include <type_traits>
extern "C" {
#endif

It seems quite ugly to escape the extern "C" from the parent like that
and then re-enter it. Overall it doesn't seem worth the hassle to me
to make these macros work in C++.

> Another consideration is what impact we have on the Rust world, and
> potentially other languages used for extensions that call C via FFI
> etc

FFI generally cannot call macros anyway, only actual symbols.



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [PATCH] Add enable_copy_program GUC to control COPY PROGRAM
Next
From: Jelte Fennema-Nio
Date:
Subject: Make copyObject work in C++