From owner-freebsd-ipfw@FreeBSD.ORG Sun Mar 7 06:16:43 2004 Return-Path: Delivered-To: freebsd-ipfw@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8093F16A4CF; Sun, 7 Mar 2004 06:16:43 -0800 (PST) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5558743D46; Sun, 7 Mar 2004 06:16:43 -0800 (PST) (envelope-from mux@freebsd.org) Received: by elvis.mu.org (Postfix, from userid 1920) id 4C5BC5C784; Sun, 7 Mar 2004 06:16:43 -0800 (PST) Date: Sun, 7 Mar 2004 15:16:43 +0100 From: Maxime Henrion To: Luigi Rizzo Message-ID: <20040307141643.GS35475@elvis.mu.org> References: <20040306111922.GA64109@numeri.campus.luth.se> <20040306082625.B34490@xorpc.icir.org> <20040306173219.GB64109@numeri.campus.luth.se> <20040306212233.A56351@xorpc.icir.org> <20040307113008.GC64109@numeri.campus.luth.se> <20040307051216.A74559@xorpc.icir.org> <20040307140915.GR35475@elvis.mu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040307140915.GR35475@elvis.mu.org> User-Agent: Mutt/1.4.1i cc: ipfw@freebsd.org cc: Johan Karlsson Subject: Re: where do %j/uintmax_t stand in terms of standards? [WAS: Re: WARNS cleanup for ipfw X-BeenThere: freebsd-ipfw@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: IPFW Technical Discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Mar 2004 14:16:43 -0000 Maxime Henrion wrote: > Luigi Rizzo wrote: > > On Sun, Mar 07, 2004 at 12:30:08PM +0100, Johan Karlsson wrote: > > ... > > > Ok, how about the attached patch then? It takes care of all printf > > > related warnings on -current. > > > > not there yet, sorry... > > > > No offense, but I think that rather than rushing for a commit you > > should wait a few days to get some feedback from people using 64-bit > > platforms (e.g. try to post to -sparc or -alpha, or ask some of > > the people involved with 64-bit development), and also have a look > > at how other system utilities deal with similar things (64-bit > > counters and possible alignment problems -- what is the preferred > > way to print out things, "%qu" or "%llu" ? I understand that > > ipfw2.c does a mix of both things, i just have no idea which one is > > better except that "unsigned long long" is a lot longer to > > write than "u_quad_t" so that might favour "%qu" ?). > > In any case, it's a weekend, give people a bit of time to read and > > think about solutions. > > The "%llu" format is preferred over "%qu", because the latter is > BSD-specific while the former is in C99 now (it was a GCC extension > before). It is correct to cast to unsigned long long and use "%llu" to > print an uint64_t because a long long is guaranteed to always be at > least 64 bits. One should however still use uint64_t to store the type > rather than unsigned long long because it may be bigger than 64 bits. > So unsigned long long should only be used for the cast here. Replying to myself : it's interesting to know that C99 introduces some macros expanding to printf() formats. Those are in inttypes.h. For instance, to print an uint64_t, one should theoritically use the PRIu64 macro, ie: `` printf("%" PRIu64 "\n", foo); ''. We actually don't use those in FreeBSD because they are simply ugly. Also, it's probably not a good idea to use this in ipfw since Luigi is concerned about keeping the code similar in 5.x and 4.x. Cheers, Maxime