Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Jun 2001 14:56:00 +1000 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
Cc:        Jonathan Lemon <jlemon@flugsvamp.com>, Jonathan Lemon <jlemon@FreeBSD.org>, cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org
Subject:   Re: cvs commit: src/usr.sbin/rarpd rarpd.c
Message-ID:  <Pine.BSF.4.21.0106171421060.97985-100000@besplex.bde.org>
In-Reply-To: <200106161821.OAA38884@khavrinen.lcs.mit.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, 16 Jun 2001, Garrett Wollman wrote:

> <<On Sat, 16 Jun 2001 11:09:40 -0500, Jonathan Lemon <jlemon@flugsvamp.com> 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0106171421060.97985-100000>