|Date:||November 8, 2006 / year-entry #378|
|Summary:||We discussed earlier the history behind the the return value of the ShellExecute function, and why its value in Win32 is meaningless aside from testing it against the value 32 to determine whether an error occurred. How, then, should you check for errors? Let's turn the question around. How would you, the implementor of the...|
We discussed earlier the history behind the the return value of the
Let's turn the question around. How would you, the implementor of the
(Now, there may be those of you who say, "Hang compatibility. If programs checked the return value incorrectly, then they deserve to stop working!" If you choose to go in that direction, then be prepared for the deluge of compatibility bugs to be assigned to you to fix. And they're going to come from a grumpy compatibility testing team because they will have spent a long time just finding out that the problem was that the program was checking the return value of
Since there is still 16-bit code out there that may thunk up to 32-bit code, you probably don't want to return a value greater than
For similar reasons, the 64-bit implementation of the
Furthermore, you shouldn't return a value that, when cast to an integer, results in a negative number. Some people will use a signed comparison against 32; others will use an unsigned comparison. If you returned a value like
By the same logic, the value you choose as the return value should not result in a negative number when cast to a 16-bit integer. If the return value is passed to a 16-bit caller that casts the result to an integer and compares against 32, you want consistent results independent of whether the 16-bit caller used a signed or unsigned comparison.
Edge conditions are tricky, so you don't want to return the value 32 exactly. If you look at code that checks the return value from
So far, you're constrained to choosing a value in the range 33–32767.
Finally, you might be a fan of Douglas Adams. (Most geeks are.) The all-important number 42 fits into this range. Your choice of return value, therefore, might be
Going back to the original question: How should I check the return value of
<-- Back to Old New Thing Archive Index