UINT32_C和uint32_t之间的区别 [英] Difference between UINT32_C and uint32_t

查看:829
本文介绍了UINT32_C和uint32_t之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知 uint32_t 中的后缀 t 表示 t 类型,但我想知道 C是什么 UINT32_C 中有什么区别?

解决方案

UINT32_C 是一个宏,它定义类型为 uint_least32_t 的整数常量。例如:

  UINT32_C(123)//可能在uint_least32_t为无符号long 
//的系统上扩展为123UL //如果uint_least32_t是unsigned int,则仅为123U。




7.20.4.1最小宽度整数常量的宏




  1. INT N _C( value 应扩展为与 int_least N _t 类型相对应的整数常量表达式
    。宏 UINT N _C( value 应该将
    扩展为一个与键入 uint_least N _t 。以
    为例,如果 uint_least64_t 是类型 unsigned long long int 的名称,则
    那么 UINT64_C(0x123)可能会扩展为整数常量 0x123ULL


因此,在某些罕见的系统上,此常数可能超过32位。



但是,如果您使用的系统中定义了多个8位2的补码类型(大多数现代系统),并且存在 uint32_t ,则这将创建32位常量



它们均在 stdint.h 中定义,自C99以来已成为C标准的一部分。 / p>

As far as I know the suffix t in uint32_t denote type name but I wonder to know what is the C in UINT32_C and what is the differences?

解决方案

UINT32_C is a macro which defines integer constant of type uint_least32_t. For example:

UINT32_C(123) // Might expand to 123UL on system where uint_least32_t is unsigned long
              // or just 123U, if uint_least32_t is unsigned int.

7.20.4.1 Macros for minimum-width integer constants

  1. The macro INTN_C(value) shall expand to an integer constant expression corresponding to the type int_leastN_t. The macro UINTN_C(value) shall expand to an integer constant expression corresponding to the type uint_leastN_t. For example, if uint_least64_t is a name for the type unsigned long long int, then UINT64_C(0x123) might expand to the integer constant 0x123ULL.

It is thus possible that this constant is more than 32 bits on some rare systems.

But if you are on a system where multiple of 8-bits 2's complement types are defined (most modern systems), and uint32_t exists, then this creates 32-bit constant.

They all are defined in stdint.h, and have been part of the C standard since C99.

这篇关于UINT32_C和uint32_t之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆