LPVOID和无效的区别* [英] Difference between LPVOID and void*

查看:91
本文介绍了LPVOID和无效的区别*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用无效*用C 而不是 LPVOID

LPVOID 执行比一些特殊功能无效*

推荐答案

有没有 LPVOID 键入C,这是一个Windows的事情。

There is no LPVOID type in C, it's a Windows thing.

和那些之类的东西存在的原因是为了让潜在的类型可以从发布变更不会影响你的源$ C ​​$ C释放。

And the reason those sort of things exists is so that the underlying types can change from release to release without affecting your source code.

例如,假设微软的C编译器的早期版本有一个16位的 INT 和一个32位的。他们可以简单地使用:

For example, let's say early versions of Microsoft's C compiler had a 16-bit int and a 32-bit long. They could simply use:

typedef long INT32

和,瞧,你有你的32位整数类型。

and, voila, you have your 32-bit integer type.

现在,让我们往前走了几年时间,微软C使用32位 INT 和一个64位的。为了正确地仍然有你的源代码code函数,它们只是将的typedef 行:

Now let's go forward a few years to a time where Microsoft C uses a 32-bit int and a 64-bit long. In order to still have your source code function correctly, they simply change the typedef line to read:

typedef int INT32

这是相对于你不得不如果你使用为您的32位整数类型该做什么。你必须要经历的所有的源$ C ​​$ C,并确保你改变了自己的定义。

This is in contrast to what you'd have to do if you were using long for your 32-bit integer types. You'd have to go through all your source code and ensure that you changed your own definitions.

这是从兼容性角度看(不同版本的Windows之间的兼容性)使用微软的数据类型干净多了。

It's much cleaner from a compatibility viewpoint (compatibility between different versions of Windows) to use Microsoft's data types.

在回答你的具体问题,它可能是没关系使用无效* 而不是 LPVOID 中的提供定义 LPVOID 预计不会改变。

In answer to your specific question, it's probably okay to use void* instead of LPVOID provided the definition of LPVOID is not expected to change.

但我不会,以防万一。你永远不知道微软是否会引入处理未来通用指针一些不同的方式,将改变 LPVOID 的定义。你真的不使用微软的类型失去任何东西,但你的可能的是,如果需要改变它们的定义做在以后的一些工作,你已经决定使用的基本类型。

But I wouldn't, just in case. You never know if Microsoft may introduce some different way of handling generic pointers in future that would change the definition of LPVOID. You don't really lose anything by using Microsoft's type but you could be required to do some work in future if they change the definition and you've decided to use the underlying type.

您可能不会想到球会幸免于这种变化,但是,在原有8088天创建的Windows的时候,里面全都是用指针和内存模型各种各样古怪的(微型,小,大,巨大的等)这使得指针是即使在同一个环境不同大小的

You may not think pointers would be immune to this sort of change but, in the original 8088 days when Windows was created, there were all sorts of weirdness with pointers and memory models (tiny, small, large, huge et al) which allowed pointers to be of varying sizes even within the same environment.

这篇关于LPVOID和无效的区别*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆