简体   繁体   English

添加指针的目的是什么:typedef unsigned char UCHAR, *PUCHAR;

[英]What is the purpose of adding a pointer in: typedef unsigned char UCHAR, *PUCHAR;

What is the purpose of adding a pointer in: typedef unsigned char UCHAR, *PUCHAR;添加指针的目的是什么: typedef unsigned char UCHAR, *PUCHAR; (there are a lot of other examples of typedefs with additional pointers) I found that next to UCHAR stands *PUCHAR pointer and checked sizeof(UCHAR) and sizeof(PUCHAR) the results was 1 byte and 8 bytes. (还有很多其他带有附加指针的 typedef 示例)我发现 UCHAR 旁边是 *PUCHAR 指针并检查了 sizeof(UCHAR) 和 sizeof(PUCHAR) 结果是 1 字节和 8 字节。 Is this pointer size fixed or is flexible?这个指针大小是固定的还是灵活的? Is that correct to make typedef with data types of different size in one line?在一行中使用不同大小的数据类型制作 typedef 是否正确? What if the OS will extend the addressing to 128 bits (16 bytes) in the future?如果操作系统将来会将寻址扩展到 128 位(16 字节)怎么办?

What is the purpose of making so much data types when it's sure, that addressing is extending?当确定寻址正在扩展时,制作这么多数据类型的目的是什么?

typedef unsigned char UCHAR, *PUCHAR;

(...) (...)

  2.2.16 HANDLE
  2.2.17 HCALL
  2.2.18 HRESULT
  2.2.19 INT
  2.2.20 INT8
  2.2.21 INT16
  2.2.22 INT32
  2.2.23 INT64
  2.2.24 LDAP_UDP_HANDLE
  2.2.25 LMCSTR
  2.2.26 LMSTR
  2.2.27 LONG
  2.2.28 LONGLONG
  2.2.29 LONG_PTR
  2.2.30 LONG32
  2.2.31 LONG64
  2.2.32 LPCSTR
  2.2.33 LPCVOID
  2.2.34 LPCWSTR
  2.2.35 LPSTR
  2.2.36 LPWSTR
  2.2.37 NET_API_STATUS
  2.2.38 NTSTATUS
  2.2.39 PCONTEXT_HANDLE
  2.2.40 QWORD
  2.2.41 RPC_BINDING_HANDLE
  2.2.42 SHORT
  2.2.43 SIZE_T
  2.2.44 STRING
  2.2.45 UCHAR
  2.2.46 UINT
  2.2.47 UINT8
  2.2.48 UINT16
  2.2.49 UINT32
  2.2.50 UINT64
  2.2.51 ULONG
  2.2.52 ULONG_PTR
  2.2.53 ULONG32
  2.2.54 ULONG64
  2.2.55 ULONGLONG
  2.2.56 UNICODE
  2.2.57 UNC
  2.2.58 USHORT
  2.2.59 VOID
  2.2.60 WCHAR
  2.2.61 WORD

UCHAR stands for unsigned char which is 1 byte in size. UCHAR 代表unsigned char ,大小为 1 个字节。 PUCHAR stands for unsigned char* . PUCHAR 代表unsigned char* To store a pointer you need 8 bytes (in a 64 bit application).要存储一个指针,您需要 8 个字节(在 64 位应用程序中)。 That's why the size of UCHAR is 1 byte and size of PUCHAR is 8 bytes.这就是为什么 UCHAR 的大小是 1 个字节而 PUCHAR 的大小是 8 个字节的原因。

Why a pointer is 8 bytes?为什么指针是 8 个字节?
That's because in a 64 bit application, the address of a single byte has 64 bits.这是因为在 64 位应用程序中,单个字节的地址有 64 位。 To represent this, you need 64 bits.为了表示这一点,您需要 64 位。 That's why it takes 8 bits.这就是为什么它需要8位。

Can't we just use *char instead of *PUCHAR or maybe it's some hidden meaning for making so much data types?我们不能只使用 *char 而不是 *PUCHAR 或者它可能是制作这么多数据类型的一些隐藏含义?

*PUCHAR is unsigned char** , not char* . *PUCHARunsigned char** ,而不是char* But if I understand your question correctly and what you mean is "using unsigned char* instead of PUCHAR ", yes you can.但是,如果我正确理解您的问题并且您的意思是“使用unsigned char*而不是PUCHAR ”,是的,您可以。 But only if you know about the underlying type.但前提是您了解基础类型。

There can be few reasons for why the developers have gone with a custom typedef like that.开发人员使用这样的自定义 typedef 的原因可能很少。 It could be to fit in multiple platforms, to fit different architectures, personal opinion, etc... Without knowing the real underlying type, we might actually lose information in the process of casting to another type.可能是为了适应多个平台,适应不同的架构,个人观点等等......在不知道真正的底层类型的情况下,我们实际上可能会在转换为另一种类型的过程中丢失信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM