cr88192 wrote:
> "Richard Heathfield" <rjh@[EMAIL PROTECTED]
> wrote in message
> news:HMudnfqSToSaMb_VnZ2dneKdnZydnZ2d@[EMAIL PROTECTED]
>> cr88192 said:
<snip>
>>> {
>>> printf("usage: %s <filename>\n", argv[0]);
>> If argc is 0, the behaviour is undefined. If it is >= 1, argv[0] must
>> represent the program name in some way, but need not be a string
>> representing the invocation name for the program. It could even be a
pid!
>
> this is a common practice though, and also I don't personally know of
any OS
> where argc is not at least 1...
<snip>
Any Unix if the exec* call used to invoke the program provides a
parameter list with argv[0]=NULL. In Unix programs other than your shell
are allowed to exec your program, so you cannot guarantee you will get a
program name.
>>> but 0 and -1 are more common/traditional.
>> A -1 return value has no de jure meaning in C (which is, at least, in
>> keeping with the better kinds of tradition - if we knew why we did
them,
>> they wouldn't be traditions!).
>>
>> To indicate failure ****tably, use EXIT_FAILURE.
>>
>
> it is more correct, but -1 is a very common value for indicating error
as
> well.
> I think usually any value other than 0 counts as an error.
<snip>
Not on VMS. IIRC on VMS odd return values indicate success and even
return values indicate failure with the C compiler using some magic to
make returning 0 actually return an odd number to the environment.
There *are* good reasons for using non-C-standard return values from
main, but in my experience they only apply when you have return return
values indicating something more than simple success/failure.
--
Flash Gordon


|