From owner-cvs-all Sat Jun 16 21:58:26 2001 Delivered-To: cvs-all@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id 7A40937B407; Sat, 16 Jun 2001 21:58:01 -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 OAA31956; Sun, 17 Jun 2001 14:57:47 +1000 Date: Sun, 17 Jun 2001 14:56:00 +1000 (EST) From: Bruce Evans X-Sender: bde@besplex.bde.org To: Garrett Wollman Cc: Jonathan Lemon , Jonathan Lemon , cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/usr.sbin/rarpd rarpd.c In-Reply-To: <200106161821.OAA38884@khavrinen.lcs.mit.edu> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Sat, 16 Jun 2001, Garrett Wollman wrote: > < said: > > > Yes - sizeof() appears to be a 'long int' on the alpha, but an 'int' > > on the i386. > > The correct way to print the result of the `sizeof' operator using > `printf()' in C89 is with the `%lu' format (and the argument cast to > `unsigned long'), and in C99 is with the `%ju' format (and the > argument cast to `uintmax_t'). This is true always, on every > architecture, and has been true since C89 introduced size_t to begin > with. These are not incorrect ways. They may be gratuitously inefficient. E.g., the value returned by sizeof() may be known to be smaller than INT_MAX, and then you can print it using %d after casting it to int. Of course, efficiency of printf is usually unimportant. Someone mentioned that `%zu' can be used in C99 for arguments of type size_t. Note that `%zu' can't be used directly in rarp_checkd(), because the argument is the sum of 2 size_t's so it might not have type size_t. `%zu' can be used after casting the sum to size_t only if it is known that the sum is smaller than SIZE_MAX. The efficiency of the printf in rarpd_checkd() is certainly not important enough to justify this optimization. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message