TONT 40633 不严谨的版本号检查

长大了,我才知道,全国的秀才都念半边。

原文链接: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的原因

发表评论

电子邮件地址不会被公开。 必填项已用*标注

 剩余字数 ( Characters available )

注:请不要在评论中插入任何链接,否则将自动被识别为垃圾评论,博主将完全看不到。

Notice: please DO NOT add any links in your comment, otherwise it would be identified as SPAM automatically.

*