windows中char *和LPSTR的区别

编程入门 行业动态 更新时间:2024-10-08 20:35:06
本文介绍了windows中char *和LPSTR的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-27 16:01:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1157082.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:区别   windows   char   LPSTR

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!