问题描述
限时送ChatGPT账号..如果这是一个基本或愚蠢的问题,我深表歉意.char*
和 LPSTR
有什么区别.其中 sizeof
在我的编译器中都给出了 4 个字节.谁能给我详细解释一下.谢谢..
I apologise if it is a basic or silly question. What is the difference between char*
and LPSTR
. where the sizeof
both gives 4 bytes in my compiler. Can someone explain me in detail. thanks..
推荐答案
LPSTR
是一个 Windows 类型,意味着无论你在什么平台上编译都是一样的在.这是一个指向字符串的长指针.
LPSTR
is a Windows type, meant to be be the same regardless of what platform you were compiling on. It's a long pointer to a string.
回到分段架构的时代(旧的 64K 分段,而不是新的基于选择器的分段内存),在那里你有小、小、中、大和巨大的内存模型,重要的是 Windows 类型始终是相同,无论 char *
是什么类型的指针.
Back in the days of segmented architecture (the old 64K segments, not the newer selector-based segmented memory), where you had tiny, small, medium, large and huge memory models, it was important that the Windows type was always the same, regardless of what type of pointer char *
was.
因此,如果您在底层类型不同的情况下使用不同的编译器,windows.h
头文件将定义 LPSTR
以弥补这一点.
So, if you complied with different compilers where the underlying types were different, the windows.h
header file would define LPSTR
to compensate for that.
例如,Borland C 可能有一个 16 位的 char *
而 LPSTR
可能必须定义为 far char *
为了它.在 char *
已经是长/远指针的编译器中,LPSTR
会使用它来代替.
For example, Borland C may have had a sixteen-bit char *
and LPSTR
may have had to be defined as far char *
for it. In a compiler where char *
was already a long/far pointer, LPSTR
would have just used that instead.
现在,对于 32 位以上的平面模型,可能真的不需要这种恶作剧,尽管它可能仍然发生在 64 位和 32 位代码之间的转换之类的事情上.尽管如此,那里定义的类型仍然在我们身边,并且仍然在使用中.
Nowadays, with 32+ bit flat models, there is probably no real need for such shenanigans, though it may still happen with things like thunking between 64-bit and 32-bit code. Still, the types defined back there are still with us and still very much in use.
这篇关于windows中char *和LPSTR的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论