ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

Tiny 'Touch' 32 bits program in C (3 kb)

<< < (4/6) > >>

Gerome:
Hello mouser
gerome please try to be more reasonable!  8)

actually Jibz' explanation was a great one I thought (regarding why anything but 0 is used to represent different error codes).

but regardless, this is just one of those cases where it's silly to go against the standard.  return codes can actually be used by other programs and i don't see a good reason not to follow convention.  just follow in the good hacker tradition and write a curse-filled paragraph in the readme about how you disagree with the standard, and then implement the standard :)
-mouser (October 01, 2006, 07:52 AM)
--- End quote ---

WTF 'standard' ?
And when APIs you're using just return 0 as ERROR, how do you consider standard as standard ?
There are several programming schools, several point of view, and mine is optimistic + API sided, where 0 means ERROR and 1 or TRUE means OK, that's all folks.

f0dder:
Yay for people who don't care about standards. Professional? *cough*

Jibz:
WTF 'standard' ?-Gerome
--- End quote ---

How about the ANSI/ISO C standard:

If the value of status is zero or EXIT_SUCCESS, an implementation-defined form of the status successful termination is returned. If the value of status is EXIT_FAILURE, an implementation-defined form of the status unsuccessful termination is returned.
--- End quote ---

Stroustrup (my K&R is in danish and I didn't want to post a translation .. it says basically the same thing though):

The int returned by main(), if any, is the program's return value to "the system." If no value is returned, the system will receive a value indicating successful completion. A nonzero value from main() indicates failure.
--- End quote ---

MSDN:

By convention, a return code of zero means that the program completed successfully.
--- End quote ---

For most programs it doesn't matter much what value you return, since nobody is ever going to inspect it anyway. But a program like touch is likely to be used in scripts and makefiles, and that's why I feel it's better to have it return the most standard values.

Jibz:
Btw, if I'm not mistaken, CreateFile returns INVALID_HANDLE_VALUE on failure, which is -1 .. so your program returns your success value of 1 even if the file does not exist.

Gerome:

Btw, if I'm not mistaken, CreateFile returns INVALID_HANDLE_VALUE on failure, which is -1 .. so your program returns your success value of 1 even if the file does not exist.
-Jibz (October 01, 2006, 10:45 AM)
--- End quote ---

Right :)
So this is a fix :
if (lngHandle && lngHandle != INVALID_HANDLE_VALUE)

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version