Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #395827

Re: u8"" c11 c23

From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c
Subject Re: u8"" c11 c23
Date 2025-12-15 14:27 -0800
Organization None to speak of
Message-ID <87ldj3tm7l.fsf@example.invalid> (permalink)
References <10d5vck$3kufd$1@dont-email.me> <875xc9p674.fsf@example.invalid> <86h5trtv72.fsf@linuxsc.com>

Show all headers | View raw


Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
[...]
>> The <uchar.h> header was introduced in C99.  In C99, C11, and C17,
>> that header defines char16_t and char32_t.  C23 introduces char8_t.
>>
>> There doesn't seem to be any way, other than checking the value of
>> __STDC_VERSION__ to determine whether char8_t is defined or not.
>> There are not *_MIN or *_MAX macros for these types, either in
>> <uchar.h> or in <limits.h>.  A test program I just wrote would have
>> been a little simpler if I could have used `#ifdef CHAR8_MAX`.

[...]

> Since C23 defines char8_t to be the same type as unsigned char,
> it seems better to just define it when it isn't there:
>
>     #include <limits.h>
>
>     #if CHAR_BIT == 8 && __STDC_VERSION__ < 202311
>     typedef unsigned char char8_t;
>     #endif

Yes.  And the test for CHAR_BIT may not be necessary, depending on the
programmer's intent.  char8_t is the same type as unsigned char even if
CHAR_BIT > 8.  Similarly, char16_t and char32_t are the same type as
uint_least16_t and uint_least32_t, respectively.

But before C23, u8"a" is a syntax error.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

u8"" c11 c23 Thiago Adams <thiago.adams@gmail.com> - 2025-10-20 15:35 -0300
  Re: u8"" c11 c23 Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-10-20 15:19 -0700
    Re: u8"" c11 c23 Thiago Adams <thiago.adams@gmail.com> - 2025-10-21 07:57 -0300
      Re: u8"" c11 c23 Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-10-21 10:26 -0700
        Re: u8"" c11 c23 Thiago Adams <thiago.adams@gmail.com> - 2025-10-21 15:04 -0300
          Re: u8"" c11 c23 Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-10-21 11:51 -0700
            Re: u8"" c11 c23 Thiago Adams <thiago.adams@gmail.com> - 2025-10-21 16:17 -0300
    Re: u8"" c11 c23 Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-12-15 11:13 -0800
      Re: u8"" c11 c23 Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-12-15 14:27 -0800
        Re: u8"" c11 c23 Thiago Adams <thiago.adams@gmail.com> - 2025-12-16 07:57 -0300
          Re: u8"" c11 c23 Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-12-16 04:17 -0800
        Re: u8"" c11 c23 Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-12-21 22:37 -0800
  Re: u8"" c11 c23 Bonita Montero <Bonita.Montero@gmail.com> - 2025-10-21 10:35 +0200
    Re: u8"" c11 c23 Thiago Adams <thiago.adams@gmail.com> - 2025-10-21 07:07 -0300
      Re: u8"" c11 c23 Bonita Montero <Bonita.Montero@gmail.com> - 2025-10-21 12:09 +0200
  Re: u8"" c11 c23 BGB <cr88192@gmail.com> - 2025-12-16 14:59 -0600

csiph-web