gpt4 book ai didi

c - BYTE、WORD 和 DWORD 宏定义

转载 作者:太空狗 更新时间:2023-10-29 16:05:36 24 4
gpt4 key购买 nike

我想了解什么是定义 BYTEWORDDWORD 宏的最佳方法,这些在答案中提到这question .

#define LOWORD(l) ((WORD)(l))
#define HIWORD(l) ((WORD)(((DWORD)(l) >> 16) & 0xFFFF))
#define LOBYTE(w) ((BYTE)(w))
#define HIBYTE(w) ((BYTE)(((WORD)(w) >> 8) & 0xFF))

以下假设是否正确:

  • BYTE 宏定义为#define BYTE __uint8_t
  • WORD 宏定义为#define WORD __uint16_t
  • DWORD 是宏定义为#define DWORD __uint32_t

如果是,为什么要转换为另一个宏而不是转换为 __uint8_t__uint16_t__uint32_t?这样写是不是为了更清晰?

我还找到了另一个question哪些答案包括 typedef,通过更多的研究,我找到了 question about comparing #define and typedef 的答案.在这种情况下使用 typedef 会更好吗?

最佳答案

这是一个可移植的解决方案:

#include <stdint.h>

typedef uint32_t DWORD; // DWORD = unsigned 32 bit value
typedef uint16_t WORD; // WORD = unsigned 16 bit value
typedef uint8_t BYTE; // BYTE = unsigned 8 bit value

关于c - BYTE、WORD 和 DWORD 宏定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47697926/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com