osargs functions and 32 bit values

Jonathan Coxhead jonathan at doves.demon.co.uk
Tue Aug 22 01:35:10 BST 2000


   On 1 Aug 00, at 21:53, David J. Ruck wrote:

 | Shouldn't all the OS_Args file pointer and extent calls use unsigned 
types,
 | bits rather than int ?

   Though you could get an extra bit by doing that, I don't like it. Bjarne 
Stroustrup also offers the advice that "gaining an extra bit by using 
unsigned types is rarely a good idea" (I paraphrase.)

   The reason is that it can introduce obscure errors. It's bad enough that

      if (strlen (s) > 1)

is different from

      if (strlen (s) - 1 > 0)

(the first does what you think, the second can never fail) without 
compounding the problem further.

   My rule of thumb is, if a quantity is only subject to bitwise operators 
(| & ~ ^) then it is declared |bits|; if it may also be used with 
arithmetic operators (+ - * / << >>) then it is declared |int|, even if it 
so happens that it will only take positive values.

   Obviously, this is a matter of taste, and that's mine :-).

        /|
 o o o (_|/
        /|
       (_/



More information about the oslib-user mailing list