[英]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
. 我在windows.h中有这个函数:
GetCommandLine()
,在UNICODE
模式下,它返回一个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). 现在,如果我深入挖掘,我可以看到
LPWSTR
是如何wchar_t*
,如果我更进一步,我发现wchar_t
是unsigned short
(16字节)或unsigned long
(32字节)。 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
在初始化中无法从'LPWSTR {aka wchar_t *}转换为'short unsigned int *'
So, does the compiler follow the same logic to find out that LPWSTR
is unsigned short*
in the end or am I wrong? 那么,编译器是否遵循相同的逻辑来发现
LPWSTR
是unsigned short*
还是我错了?
wchar_t
is a distinct type that is defined to have the same properties as one of the other integer types. wchar_t
是一个不同的类型,被定义为具有与其他整数类型相同的属性。
Type
wchar_t
is a distinct type [...].类型
wchar_t
是一种独特的类型[...]。 Typewchar_t
shall have the same size, signedness, and alignment requirements (3.11) as one of the other integral types, called its underlying type .类型
wchar_t
应具有与其他整数类型之一相同的大小,符号和对齐要求(3.11),称为其基础类型 。
So you can't implicitly convert from a wchar_t*
to a short*
just as much as from an int*
to a short*
. 因此,您无法隐式地将
wchar_t*
转换为short*
,就像从int*
转换为short*
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.