groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [groff] [off-topic] Reliable use of errno


From: Colin Watson
Subject: Re: [groff] [off-topic] Reliable use of errno
Date: Mon, 20 Aug 2018 10:31:46 +0100
User-agent: NeoMutt/20170113 (1.7.2)

On Sun, Aug 19, 2018 at 03:08:26PM +0100, Ralph Corderoy wrote:
> Hi Colin,
> 
> > Writing "== -1" implies a reading that any other value would indicate
> > success;
> 
> Or it implies it's being coded to the spec.

If your program explicitly handles unspecified return values and handles
those as an error case but without making reference to errno, then you
might have a point, but in practice I've never seen anyone doing this,
probably because it's excessively pedantic and noisy for no real
benefit.

Otherwise, your programming style is implicitly choosing whether you
handle unspecified return values as success or failure; for instance, if
you only handle errors within an "== -1" condition, you're implicitly
saying that unspecified return values are successes.  IME, most
programmers don't care either way, and I would argue they are correct
not to waste brain cells or program text on it.

> > writing "!= 0" implies a reading that any other value would indicate
> > an error; writing "< 0" implies a reading that it depends on the sign
> > of the hypothetical not-zero-or-minus-one return value.
> 
> Both of these allow for more values than -1, `stuttering' the human
> reader, and potentially troubling the static analyser.

Since both the practices in my quoted text above are extremely
widespread, I dispute your unsupported claim that this could trouble
static analysers: any static analyser capable of handling typical C code
must be able to handle both.  (I would be inclined to say the same for
human readers, TBH, although as usual picking one style within a project
and sticking to it is helpful.)

-- 
Colin Watson                                       address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]