Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: error_t proposal Date: Thu, 05 Sep 2019 14:31:48 -0700 Organization: None to speak of Lines: 44 Message-ID: References: <5d03868d-22f7-4c7f-9f9b-1e70d8d8e6f2@googlegroups.com> <5d70c108$0$14374$426a74cc@news.free.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="808e9da1912e399f965b4512b95a962e"; logging-data="32615"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19EPE3ME9aADzq0JMugdbV8" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:Yrxgu759cdOkOWBLJ3ovcYgoQts= sha1:DkJo1QZRFLIc3m756LMs7vwpmzI= Xref: csiph.com comp.lang.c:146043 Bruce S writes: > On 9/5/19 5:04 AM, Thiago Adams wrote: >> On Thursday, September 5, 2019 at 5:02:25 AM UTC-3, Mateusz Viste wrote: >>> On Wed, 04 Sep 2019 15:20:06 -0700, Keith Thompson wrote: >>>> Thiago Adams writes: >>>>> Some libraries uses 0 to say "no error" and others use 1 or true do say >>>>> "no error". >>>> [...] >>>> >>>> What libraries use 1 to denote "no error"? >>>> >>>> In my experience, error codes in C are almost always zero for success, >>>> non-zero for failure (with either the value or errno providing more >>>> information about the error). (My experience does have a >>>> UNIX/POSIX/Linux bias.) >>> >>> Your experience missed inet_pton() then. :) >>> But yes - it is quite an exception. >> >> Windows API has several functions returning BOOL where non zero >> is success. Zero is error and then GetLastError is used. >> >> BOOL DeleteFileA(LPCSTR lpFileName); > > IIRC from my VAX days, their library functions returned an odd value for > success, an even one for error. So 1 would be *one of* the many, many > values denoting "no error". Unfortunately, the libraries we built to > work in that environment followed the same approach. I don't recall > ever having code that depended on exactly which "success" code was > returned, though there were plenty that depended on specific errors. VMS (VAX is the hardware, which can also run Unix) does the same for the return status of a program -- which is probably part of the reason we have the EXIT_SUCCESS and EXIT_FAILURE macros in . When I worked on VMS, I sometimes ran into C programs that used "return 1;" or "exit(1);" to indicate failure, but that indicates success on VMS. (But "return 0;" or "exit(0);" is required to return a successful status, even though the OS treats that as a failure code.) -- Keith Thompson (The_Other_Keith) kst-u@mib.org Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */