为什么 stdatomic.h 包含 atomic_uint_least16_t 和 atomic_uint_fast16_t 但不包含 atomic_uint16_t?

Jas*_*n S 4 c language-lawyer stdint c11 stdatomic

stdatomic.h似乎包含 atomic_uint_least16_tand atomic_uint_fast16_t,它们是and类型的_Atomic版本,但它不包含. 为什么?stdint.h uint_least16_tuint_fast16_tatomic_uint16_t


有关N1548 草案的一些背景信息:

7.18.1.1 精确宽度整数类型

1 typedef 名称intN_t指定宽度为 N、无填充位和二进制补码表示的有符号整数类型。因此,int8_t表示具有恰好 8 位宽度的这种有符号整数类型。

2 typedef 名称uintN_t指定宽度为 N 且无填充位的无符号整数类型。因此,uint24_t表示具有恰好 24 位宽度的这种无符号整数类型。

3 这些类型是可选的。但是,如果实现提供宽度为 8、16、32 或 64 位、无填充位且(对于有符号类型)具有二进制补码表示的整数类型,则应定义相应的 typedef 名称。

7.18.1.2 最小宽度整数类型

1 typedef 名称int_leastN_t指定宽度至少为 N 的有符号整数类型,这样尺寸较小的有符号整数类型都不会至少具有指定的宽度。因此,int_least32_t表示宽度至少为 32 位的有符号整数类型。

2 typedef 名称uint_leastN_t指定宽度至少为 N 的无符号整数类型,因此没有较小尺寸的无符号整数类型至少具有指定的宽度。因此,uint_least16_t表示宽度至少为 16 位的无符号整数类型。

3 需要以下类型:

int_least8_t
int_least16_t
int_least32_t
int_least64_t
uint_least8_t
uint_least16_t
uint_least32_t
uint_least64_t
Run Code Online (Sandbox Code Playgroud)

此表格的所有其他类型都是可选的。

(以此类推,包括int_fastN _t/ uint_fastN_t类型等)

第 3 段值得强调:

但是,如果实现提供宽度为 8、16、32 或 64 位、无填充位且(对于有符号类型)具有二进制补码表示的整数类型,则应定义相应的 typedef 名称。

这意味着,例如,如果我有一个像intshort这样的类型,它被实现为具有二进制补码表示的 16 位整数,那么实现定义int16_t.

N1548中也列出了foratomic_类型(下面转载),但它没有做出相应的要求,即如果实现有一个,那么就有一个--- 这就是我的问题的性质。<stdatomic.h>int16_tatomic_int16_t

7.17.6 原子整数和地址类型

1 对于下表中的每一行,原子类型名称被声明为相应的直接类型。

Atomic type name         Direct type
----------------         -----------
atomic_char              _Atomic char
atomic_schar             _Atomic signed char
atomic_uchar             _Atomic unsigned char
atomic_short             _Atomic short
atomic_ushort            _Atomic unsigned short
atomic_int               _Atomic int
atomic_uint              _Atomic unsigned int
atomic_long              _Atomic long
atomic_ulong             _Atomic unsigned long
atomic_llong             _Atomic long long
atomic_ullong            _Atomic unsigned long long
atomic_char16_t          _Atomic char16_t
atomic_char32_t          _Atomic char32_t
atomic_wchar_t           _Atomic wchar_t
atomic_int_least8_t      _Atomic int_least8_t
atomic_uint_least8_t     _Atomic uint_least8_t
atomic_int_least16_t     _Atomic int_least16_t
atomic_uint_least16_t    _Atomic uint_least16_t
atomic_int_least32_t     _Atomic int_least32_t
atomic_uint_least32_t    _Atomic uint_least32_t
atomic_int_least64_t     _Atomic int_least64_t
atomic_uint_least64_t    _Atomic uint_least64_t
atomic_int_fast8_t       _Atomic int_fast8_t
atomic_uint_fast8_t      _Atomic uint_fast8_t
atomic_int_fast16_t      _Atomic int_fast16_t
atomic_uint_fast16_t     _Atomic uint_fast16_t
atomic_int_fast32_t      _Atomic int_fast32_t
atomic_uint_fast32_t     _Atomic uint_fast32_t
atomic_int_fast64_t      _Atomic int_fast64_t
atomic_uint_fast64_t     _Atomic uint_fast64_t
atomic_intptr_t          _Atomic intptr_t
atomic_uintptr_t         _Atomic uintptr_t
atomic_size_t            _Atomic size_t
atomic_ptrdiff_t         _Atomic ptrdiff_t
atomic_intmax_t          _Atomic intmax_t
atomic_uintmax_t         _Atomic uintmax_t
Run Code Online (Sandbox Code Playgroud)

2 这些类型的操作的语义在 7.17.7 中定义。

3 该atomic_bool类型提供了一个原子布尔值。

4 该atomic_address类型提供原子 void * 操作。加减法的单位为一字节。

5 注意原子整数和地址类型的表示不需要与其对应的常规类型具有相同的大小。它们应尽可能具有相同的大小,因为这样可以减轻移植现有代码所需的工作量。

Jen*_*edt 5

这个专门的原子类型列表只是因为历史性的事故而存在,它们旨在确保与 C++ 的兼容性。而且,它们只是为了为强制的整数类型提供接口。这些uintXX_t类型都不是强制性的,因此不包括在内。

(这个进球立刻加入浇水atomic_[u]intprt_t那里[u]intptr_t不是强制性的,但可能是另一个故事。)