httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From (Dean Gaudet)
Subject Re: cvs commit: apache/src util.c
Date Wed, 13 Nov 1996 19:55:35 GMT
As I mentioned, inet_addr/inet_network return -1 on Solaris, and return
INADDR_NONE on Linux and IRIX.  -1 is wrong, ~0ul is wrong, and INADDR_NONE
is wrong too -- unless we use autoconf or stick something else in conf.h.
So either we choose one of those wrongnesses and live with it, or we
switch to inet_aton, or we use autoconf.  I know how much some people
like that last option (for reasons I can't fathom at all).

Nothing you put there will be portable.  Some things will be more portable
than others.  I'm sorry I even mentioned ~0ul, because I knew it would
lead to someone quoting ANSI and saying "only if it's a twos-complement
machine!".  Yeah there's so many non-twos-complement machines rolling
off the production lines in the past 16 years which run unix.


In article <>,
Paul Richards  <> wrote:
>Roy Fielding <> writes:
>>   !     if (my_addr != (~0ul))
>Ahh, no. Ben's right. The function returns -1, since the return type
>is unsigned long it'll be -1 cast to an unsigned long. The correct fix
>is as Ben said (unsigned long) -1 since this is what the function is
>actually returning and we should test for the same construct.
>Assuming an 8 bit representation (save me typing lots of 1's).
>The representation of ~0ul is 11111111. That's a positive value that is
>the 1's complement (which is what the ~ operator is) of 0 i.e. the
>largest positive value representable. This is most definately *NOT*
>the same as an integral conversion, in fact, an integral conversion
>takes place on signed numbers as part of the ~ operator's behaviour.
>To quote (integral conversions A6.2 K&RII).
>	"Any integer is converted to a given unsigned type by finding
>	 the smallest non-negative value that is congruent to that
>	 integer, modulo one more than the largest value that can be
>	 represented in the unsigned type. In a two's complement
>	 represenatation, this is equivalent to left-truncation if the
>	 bit pattern of the unsigned type is narrower, and to
>	 zero-filling unsigned values and sign-extending if the
>	 unsigned type is wider."
>Since we're all using 2's complement based machines we're not likely
>to see any difference between ~0ul and (unsigned long) -1 but that's
>only because we're relying on a particular implementation of the
>language and not because ~0ul is correct since it clearly isn't.
>  Paul Richards. Originative Solutions Ltd.  (Netcraft Ltd. contractor)
>  Elsevier Science TIS online journal project.
>  Email:
>  Phone: 0370 462071 (Mobile), +44 (0)1865 843155

View raw message