From owner-freebsd-current Sun Mar 12 19:42:45 2000 Delivered-To: freebsd-current@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id 7AFEE37B61F for ; Sun, 12 Mar 2000 19:42:41 -0800 (PST) (envelope-from bde@zeta.org.au) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.8.7/8.8.7) with ESMTP id OAA06332; Mon, 13 Mar 2000 14:48:43 +1100 Date: Mon, 13 Mar 2000 14:42:05 +1100 (EST) From: Bruce Evans X-Sender: bde@alphplex.bde.org To: John Polstra Cc: keramida@ceid.upatras.gr, current@FreeBSD.ORG Subject: Re: MAX_UID ? In-Reply-To: <200003130151.RAA51453@vashon.polstra.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Sun, 12 Mar 2000, John Polstra wrote: > In article <20000313015009.A5653@hades.hell.gr>, > Giorgos Keramidas wrote: > > On Sun, Mar 12, 2000 at 05:59:09AM +0000, Paul Richards wrote: > > > > > > Are expressions like ((uid_t)0-1) portable/safe ? Maybe that's a better > > > way of approaching this. > > > > To get the all-1's number, maybe it's better to use ((uid_t)~0), but > > that is a rather controversial topic anyway. > > That works, but on machines like the Alpha where longs are bigger > than ints it only works by virtue of sign extension. Our existing > headers seem to prefer ((uid_t)0-1). That's what is used in the > i386's . All 3 of these are broken in general. ((uquad_t)0-1) in works because it is known that uquad_t is no smaller than int. If foo_t is smaller than int, then (foo_t)0 in an expression gets promoted to plain 0, which is rarely what you want. ((uid_t)~(uid_t)0) is probably best. The first cast gives a sufficient number of 0 bits and the second cast discards unwanted 1 bits. -1 is sometimes used instead of ~0 because there is a good rule for converting -1 to an unsigned type. I can never quite remember this rule, so I prefer to use ~something. Part of the rule is that (unsigned int)-1 has all bits 1 even if -1 doesn't have all bits 1. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message