简体   繁体   中英

LPWSTR, wchar_t* and unsigned short pointer in C++

I'm trying to understand if these types are all the same. I have this function from windows.h : GetCommandLine() , in UNICODE mode, and it returns a LPWSTR . Now, if I dig deeper I can see how LPWSTR is wchar_t* and if I go even further, I find out that wchar_t is unsigned short (16 bytes) or unsigned long (32 bytes). Yet, if I do this:

unsigned short* SysComm = GetCommandLine();

I get this error:

cannot convert from 'LPWSTR {aka wchar_t*} to 'short unsigned int*' in initialization

So, does the compiler follow the same logic to find out that LPWSTR is unsigned short* in the end or am I wrong?

wchar_t is a distinct type that is defined to have the same properties as one of the other integer types.

Type wchar_t is a distinct type [...]. Type wchar_t shall have the same size, signedness, and alignment requirements (3.11) as one of the other integral types, called its underlying type .

So you can't implicitly convert from a wchar_t* to a short* just as much as from an int* to a short* .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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