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此表格的所有其他类型都是可选的。
(依此类推,要包括int_fastN _t/ uint_fastN_t类型等)
第 3 段值得强调:
但是,如果实现提供了宽度为 8、16、32 或 64 位的整数类型,没有填充位,并且(对于有符号类型)具有二进制补码表示,则它应定义相应的 typedef 名称。
这意味着,例如,如果我有一个类似intor的类型,short它被实现为具有二进制补码表示的 16 位整数,那么实现应定义int16_t.
的atomic_类型<stdatomic.h>也列在N1548中(转载如下),但它没有做出相应的要求,即如果实现有 aint16_t则有atomic_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_t2 对这些类型的操作的语义在 7.17.7 中定义。
3 该
atomic_bool类型提供一个原子布尔值。4 该
atomic_address类型提供原子 void * 操作。加/减的单位应为一个字节。5 注意原子整数和地址类型的表示不需要与它们对应的常规类型具有相同的大小。它们应该尽可能具有相同的大小,因为它可以减轻移植现有代码所需的工作量。