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 [cjwat...@debian.org]