DragonFly BSD
DragonFly commits List (threaded) for 2005-03
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: cvs commit: src/lib/libc/sys tls.2

From: Matthew Dillon <dillon@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 21 Mar 2005 11:37:27 -0800 (PST)

:On Mon, 21 Mar 2005 11:15:32 -0800 (PST)
:Matthew Dillon <dillon@xxxxxxxxxxxxxxxxxxxx> wrote:
:>     Grumble (Matt goes off in a corner and mumbles about stupid standards
:>     which use unsigned ints because some bozo wanted to write 2.1GB of data
:>     in one go, when they really ought to just use normal ints).
:Why ought they do that?
:(or: why would one ever want a *negative* infosize?!)

    It's not that, it's the same issue with sizeof() returning unsigned
    when it really just ought to return an int.  Unsigned quantities change
    the way expressions in code are handled in ways that are not always
    apparent.  For example, if you are doing a delta calculation you can't
    just do the calculation and check to see if the result is negative,
    instead you have to do a range check before you do the calculation. 
    Things like that.  Negative numbers are also very useful as a means of
    representing out of band data or conditions.  EOF == -1 is a good example.
    Another is the handling of an optional argument.  If 0 is an allowed
    value then you can initialize an option to -1 to indicate that it has
    not been issued.  so, e.g. an optional 'int size_opt' argument, instead
    of 'int size; int size_opt_is_valid;'.  But with size_t you then have
    to cast it to an unsigned.  It just makes life unnecessarily difficult
    when 99.9999% of the calls to all these routines never need to specify
    huge blocks.

    In the case of a memory block, I suppose 'long' would be a better choice
    then 'int', but I really hate the way the hidden unsignedness of size_t
    and sizeof() has infiltrated the standards.

					Matthew Dillon 

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