-5

What is the purpose of adding a pointer in: 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. Is this pointer size fixed or is flexible? Is that correct to make typedef with data types of different size in one line? What if the OS will extend the addressing to 128 bits (16 bytes) in the future?

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
SmilingMouse
  • 132
  • 1
  • 2
  • 15
  • 2
    One is a pointer the other is not. `UCHAR` is an unsigned char. PUCHAR is a pointer to an unsigned char. – drescherjm Jan 17 '21 at 18:12
  • 1
    No a pointer is usually 64 bits in a 64 bit program regardless of what type it points to. – drescherjm Jan 17 '21 at 18:15
  • 1
    Can you edit your question to remove the rant, the antagonizing language and profanities? As written this question does not fit community guidelines. – sehe Feb 06 '21 at 16:55
  • Please use workplace-appropriate language on Stack Overflow, not language which may be offensive to some people or groups of people. Please see: [Are expletives (cursing, swear words or vulgar language) allowed on SE sites?](//meta.stackexchange.com/questions/22232/are-expletives-cursing-swear-words-or-vulgar-language-allowed-on-se-sites). Keep in mind that using offensive language tends to result in people reacting poorly to your posts (i.e. they may downvote). In addition, do you really want a future employer to see you using such language in a situation which is intended to be professional? – Makyen Feb 06 '21 at 18:07
  • 1
    Editing Questions to improve them (e.g. clarification, adding additional information, etc.) *is encouraged*. However, editing a Question to change it into a different question which results in invalidating one or more Answers, is against Stack Exchange policy (even when your original question wasn't what you intended). Your most recent edit here did invalidate an answer. In such cases, you *are encouraged to [ask a new Question](/questions/ask)* instead, perhaps with a link to this one for additional context. – Makyen Feb 06 '21 at 18:29

1 Answers1

1

UCHAR stands for unsigned char which is 1 byte in size. PUCHAR stands for unsigned char*. To store a pointer you need 8 bytes (in a 64 bit application). That's why the size of UCHAR is 1 byte and size of PUCHAR is 8 bytes.

Why a pointer is 8 bytes?
That's because in a 64 bit application, the address of a single byte has 64 bits. To represent this, you need 64 bits. That's why it takes 8 bits.

Can't we just use *char instead of *PUCHAR or maybe it's some hidden meaning for making so much data types?

*PUCHAR is unsigned char**, not char*. But if I understand your question correctly and what you mean is "using unsigned char* instead of PUCHAR", yes you can. 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. 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.

D-RAJ
  • 3,263
  • 2
  • 6
  • 24
  • Could you addres "Can't we just use *char instead of *PUCHAR or maybe it's some hidden meaning for making so much data types?" as well? I feel about 80% of the question focuses on the "type pollution" aspect – sehe Feb 06 '21 at 16:51
  • @sehe I added it. – D-RAJ Feb 06 '21 at 17:10
  • 1
    @SmilingMouse `UCHAR = unsigned char`, `PUCHAR = unsigned char*`, `PUCHAR* = unsigned char**`. Hope this clears out your doubts. – D-RAJ Feb 07 '21 at 05:19