Re: C11: should we use char32_t for unicode code points?
Peter Eisentraut <peter@eisentraut.org>
From: Peter Eisentraut <peter@eisentraut.org>
To: Jeff Davis <pgsql@j-davis.com>, Thomas Munro <thomas.munro@gmail.com>
Cc: Tatsuo Ishii <ishii@postgresql.org>, pgsql-hackers@postgresql.org
Date: 2025-10-28T18:45:18Z
Lists: pgsql-hackers
This patch looks good to me overall, it's a nice improvement in clarity. On 26.10.25 20:43, Jeff Davis wrote: > +/* > + * char16_t and char32_t > + * Unicode code points. > + */ > +#ifndef __cplusplus > +#ifdef HAVE_UCHAR_H > +#include <uchar.h> > +#ifndef __STDC_UTF_16__ > +#error "char16_t must use UTF-16 encoding" > +#endif > +#ifndef __STDC_UTF_32__ > +#error "char32_t must use UTF-32 encoding" > +#endif > +#else > +typedef uint16_t char16_t; > +typedef uint32_t char32_t; > +#endif > +#endif This could be improved a bit. The reason for some of these conditionals is not clear. Like, what does __cplusplus have to do with this? I think it would be more correct to write a configure/meson check for the actual types rather than depend indirectly on a header check. The checks for __STDC_UTF_16__ and __STDC_UTF_32__ can be removed, as was discussed elsewhere, since we don't use any standard library functions that make use of these facts, and the need goes away with C23 anyway.
Commits
-
Use C11 char16_t and char32_t for Unicode code points.
- 3853a6956c3e 19 (unreleased) landed
-
Move comment about casts from pg_wchar.
- 4da12e9e2e3c 19 (unreleased) landed
-
Comment typo fixes: pg_wchar_t should be pg_wchar.
- 371a302eecdc 19 (unreleased) landed