From owner-freebsd-arch Mon Jul 9 0:50:36 2001 Delivered-To: freebsd-arch@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id 6765737B403 for ; Mon, 9 Jul 2001 00:50:32 -0700 (PDT) (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.9.3/8.8.7) with ESMTP id RAA22830; Mon, 9 Jul 2001 17:50:24 +1000 Date: Mon, 9 Jul 2001 17:48:19 +1000 (EST) From: Bruce Evans X-Sender: bde@besplex.bde.org To: Dag-Erling Smorgrav Cc: arch@FreeBSD.ORG Subject: Re: Type differences In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On 8 Jul 2001, Dag-Erling Smorgrav wrote: > des@des /usr/src/sys% grep 'define.*BSD_SIZE_T' {i386,alpha}/include/ansi.h > i386/include/ansi.h:#define _BSD_SIZE_T_ unsigned int /* sizeof() */ > alpha/include/ansi.h:#define _BSD_SIZE_T_ unsigned long /* sizeof() */ > des@des /usr/src/sys% grep 'define.*BSD_OFF_T' {i386,alpha}/include/ansi.h > i386/include/ansi.h:#define _BSD_OFF_T_ __int64_t /* file offset */ > alpha/include/ansi.h:#define _BSD_OFF_T_ long /* file offset */ > > What's the idea here? off_t is the exact same size and signedness on > both platforms, so why not use the same definition for both? The idea is that _BSD_FOO_T_ should have a basic (ISO C90) type so that doesn't have convoluted dependencies on the files that declare typedefed types. This is not possible for _BSD_OFF_T_, so it is handled specially (see rev.15 of the i386 version). > And why > make size_t an int on i386 but a long on alpha, when on both these > platforms int and long are identical? _BSD_SIZE_T_ is different because it _is_ different. 1. int and long aren't identical. The difference may be just in their spelling, but it affects the whole type system. 2. int and long don't even have the same size on alphas under FreeBSD. 3. doesn't get to choose the type of _BSD_SIZE_T_. It must match the type of the compiler's sizeof() operator. This is specified by the SIZE_TYPE macro in gcc/cppdefault.h and gcc/config/${MACHINE_ARCH}/*. It defaults to "long unsigned int", but for historical reasons it is "unsigned int" on i386's. > Also, gcc (correctly) complains about a "comparison between signed and > unsigned" when you try to compare a size_t to an off_t on alpha - but > doesn't complain on i386. What gives? On i386's, size_t is 32 bits unsigned. For the comparison, size_t's are promoted to a common type. off_t is longer, so size_t is first promoted to 64 bits signed (it loses its unsignedness due to ISO C's (BAD) value-preserving (signedness-clobbering) promotion rule). off_t is also 64 bit signed, so no further promotion occurs. Both operands are now signed, so gcc doesn't complain. Not that there is still a bug if it is possible for the off_t to have a negative value; signedness-clobbering promotion has mainly broken the warning for i386's. > And while we're on this subject, what's the Officially Approved way of > printf()ing an off_t or a size_t so it does not generate warnings on > either platform? Implement the ISO C99 [u]intmax_t and %j[diouxX] and use them. You could also implement and use %z[diouxX] for size_t's and %t[diouxX] for ptrdiff_t's. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message