Re: Documentation of abs(3), div(3) etc.

Krister Walfridsson <[email protected]>
Newsgroups gmane.os.netbsd.devel.general
Message-ID <[email protected]>
On Fri, 9 Feb 2007, Alan Barrett wrote:

>>> the manpages for abs(3) and its variants define behavior for the
>>> "most negative integer" whereas the standard explicity states that
>>> the behavior is undefined if the result cannot be represented.
>
> I'd like out man page to both document what we do, and document what
> parts of that are non-standard.  At present, out abs(3) seems to
> accurately document what we do, but not that part of it is undefined by
> the standard.

But the current code does in fact invoke undefined behavior when
called with the value of the most negative integer.  :)

And gcc does recognize abs() and will generate code directly and optimize 
it using the definition as written in the standard.  I.e. the libc abs() 
will in general not be called, so users cannot rely on any "extensions" 
anyway.


I think it is better to update the man page to say the same thing as
the standard, instead of uglifying the implementation with casts
and crippling gcc in random ways...

    /Krister
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.