N
Nick Keighley
The core problem underlying all of this - is the fact that the shell treats
a return value of 0 as "TRUE" and anything else (i.e., non-zero) as FALSE..
Which is the exact opposite of what C (and most other programming languages)
do. Hence the confusion. Digging further, what underlies that is a basic
intuitive feeling that "TRUE" should be "good" and FALSE "bad", which, I
think, corresponds with most people's basic feelings about the Universe.
Interestingly enough, the first platform I ever used that used the concept
of TRUE/FALSE to indicate error/success, did so in that order - namely,
TRUE == error and FALSE == success. Counterintuitive this was,but it got
the job done nicely.
Finally, note that the Windows API mostly follows the model that 0 ==failure,
1 (although this is usually documented as "non-zero") == success, because
this is what most people (unless they've come from a Unix background) expect
and are comfortable with, even though it is technically less efficient.
annoyingly I sometimes see code that returns a bool result for such a
convention. (I'm not sure if MS do this though)
ah yes this is what I was thinking:-
************************************
BOOL WINAPI DeleteFile(
_In_ LPCTSTR lpFileName
);
Return value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero (0). To get extended
error information, call GetLastError.
************************************
A sane convention I just wish they hadn't called it BOOL!
<snip>