为什么标准数据类型不是Win32 API的使用? [英] Why are the standard datatypes not used in Win32 API?

查看:132
本文介绍了为什么标准数据类型不是Win32 API的使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在学习的Visual C ++ Win32编程有一段时间了。
为什么有像 DWORD WCHAR UINT 的数据类型等来代替,比如说,无符号长字符 unsigned int类型等等?

I have been learning Visual C++ Win32 programming for some time now. Why are there the datatypes like DWORD, WCHAR, UINT etc. used instead of, say, unsigned long, char, unsigned int and so on?

我要记住什么时候使用,而不是为const char * WCHAR,这是真的讨厌我。
为什么不在第一位置中使用的标准的数据类型?如果我记忆Win32等效,并利用这些为我自己的变量,以及它会帮助?

I have to remember when to use WCHAR instead of const char *, and it is really annoying me. Why aren't the standard datatypes used in the first place? Will it help if I memorize Win32 equivalents and use these for my own variables as well?

推荐答案

是的,你应该使用正确的数据类型为参数的功能,或者你可能会发现自己有麻烦了。

Yes, you should use the correct data-type for the arguments for functions, or you are likely to find yourself with trouble.

和这些类型的定义他们的方式,而不是使用的原因 INT 字符等就在于它消除了无论编译器认为一个 INT 的大小应为从操作系统的界面。这是一个非常好的事情,因为如果你使用的编译器,编译或B,或编译C,它们都将使用相同​​类型的 - 只有库接口的头文件需要做的定义类型正确的事情。

And the reason that these types are defined the way they are, rather than using int, char and so on is that it removes the "whatever the compiler thinks an int should be sized as" from the interface of the OS. Which is a very good thing, because if you use compiler A, or compiler B, or compiler C, they will all use the same types - only the library interface header file needs to do the right thing defining the types.

通过定义不是标准类型的类型,很容易改变 INT 16到32位,例如。第一个C / C ++为Windows编译器采用16位整数。只是在中后期90年代的Windows有一个32位的API,并且直到这一点,你使用 INT 这是16位。试想一下,你有一个使用几百 INT 变量一个良好的工作程序,突然,你必须对所有这些变量的改变别的东西......止跌'T是非常好的,正确的 - 尤其是因为一些这些变量不需要改变,因为迁移到32位int一些您的code将没有任何区别,所以没有一点改变那些位。

By defining types that are not standard types, it's easy to change int from 16 to 32 bit, for example. The first C/C++ compilers for Windows were using 16-bit integers. It was only in the mid to late 1990's that Windows got a 32-bit API, and up until that point, you were using int that was 16-bit. Imagine that you have a well-working program that uses several hundred int variables, and all of a sudden, you have to change ALL of those variables to something else... Wouldn't be very nice, right - especially as SOME of those variables DON'T need changing, because moving to a 32-bit int for some of your code won't make any difference, so no point in changing those bits.

应该指出的是, WCHAR 是不一样的为const char - WCHAR 是宽字符,所以 wchar_t的是可比的类型。

It should be noted that WCHAR is NOT the same as const char - WCHAR is a "wide char" so wchar_t is the comparable type.

所以,基本上,定义我们自己的类型,就是要保证它有可能改变底层架构编译器的方式,而不必更改(大部分)的源$ C ​​$ C。那些依赖于机器的编码所有的大型项目做这样的事情。

So, basically, the "define our own type" is a way to guarantee that it's possible to change the underlying compiler architecture, without having to change (much of the) source code. All larger projects that do machine-dependant coding does this sort of thing.

这篇关于为什么标准数据类型不是Win32 API的使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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