Received: by taz.hyperreal.com (8.7.6/V2.0) id DAA10231; Wed, 13 Nov 1996 03:23:54 -0800 (PST) Received: from pillar.elsevier.co.uk by taz.hyperreal.com (8.7.6/V2.0) with ESMTP id DAA10214; Wed, 13 Nov 1996 03:23:44 -0800 (PST) Received: from snowdon.elsevier.co.uk (snowdon.elsevier.co.uk [193.131.197.164]) by pillar.elsevier.co.uk (8.8.2/8.8.2) with ESMTP id LAA23976 for ; Wed, 13 Nov 1996 11:23:23 GMT Received: from cadair.elsevier.co.uk by snowdon.elsevier.co.uk with SMTP (PP); Wed, 13 Nov 1996 11:23:00 +0000 Received: from tees.elsevier.co.uk (tees.elsevier.co.uk [193.131.197.60]) by cadair.elsevier.co.uk (8.8.2/8.8.0) with ESMTP id LAA20173 for ; Wed, 13 Nov 1996 11:22:53 GMT Received: (from dpr@localhost) by tees.elsevier.co.uk (8.8.2/8.8.0) id LAA26073; Wed, 13 Nov 1996 11:21:44 GMT To: new-httpd@hyperreal.com Subject: Re: cvs commit: apache/src util.c References: <199611121824.KAA22783@taz.hyperreal.com> From: Paul Richards Date: 13 Nov 1996 11:21:43 +0000 In-Reply-To: Roy Fielding's message of Tue, 12 Nov 1996 10:24:41 -0800 (PST) Message-ID: <577mnqqlyw.fsf@tees.elsevier.co.uk> Lines: 38 X-Mailer: Gnus v5.3/Emacs 19.30 Sender: owner-new-httpd@apache.org Precedence: bulk Reply-To: new-httpd@hyperreal.com 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: p.richards@elsevier.co.uk Phone: 0370 462071 (Mobile), +44 (0)1865 843155