请注意:本页内容发布于 2178 天前,内容可能已经过时,请注意甄别。
长大了,我才知道,全国的秀才都念半边。
原文链接:https://blogs.msdn.microsoft.com/oldnewthing/20040213-00/?p=40633
Version numbers. Very important. And so many people check them wrong.
版本号,非常重要,却拦不住那么多人用错误的方式做检查。
This is why Windows 95’s GetVersion function returned 3.95 instead of 4.0. A lot of code checked the version number like this:
这就是Windows 95的GetVersion函数为什么返回的是3.95而不是4.0的原因,因为这世上有那么多代码都是如下这样检查系统的版本号的:
UINT Ver = GetVersion();
UINT MajorVersion = LOBYTE(uVer);
UINT MinorVersion = HIBYTE(uVer);
if (MajorVersion < 3 || MinorVersion < 10) {
Error(“This program requires Windows 3.1”); //译注:意为『此程序需要Windows 3.1』
}
Now consider what happens when the version number is reported as 4.0. The major version check passes, but the minor version check fails since 0 is less than 10.
现在来思考一下以上代码遇到系统报告的4.0版本号会发生什么。主版本号检查通过了,但次版本号过不了,因为0比10小。(译注:注意MajorVersion和MinorVersion之间是『或』关系)
This bug was so rife that we gave up shimming every app that had the problem and just decided, “Fine. If anybody asks, say that the Windows version is 3.95.”
这个bug实在是太流行了,以至于我们干脆放弃了为每个存在该问题的应用打补丁的做法,并决定:『×它〇的,再有人问,就说Windows的版本是3.95得了。』
I suspect this is also why DirectX always reports its version as 4.x.
我想这也是为什么DirectX总是报告其版本为4.x的原因。
远嚣 Comment