From owner-freebsd-hackers@FreeBSD.ORG Thu Sep 18 21:37:56 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BA11A1065675 for ; Thu, 18 Sep 2008 21:37:56 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (bigknife-pt.tunnel.tserv9.chi1.ipv6.he.net [IPv6:2001:470:1f10:75::2]) by mx1.freebsd.org (Postfix) with ESMTP id 2DBBA8FC16 for ; Thu, 18 Sep 2008 21:37:55 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from localhost.corp.yahoo.com (john@localhost [IPv6:::1]) (authenticated bits=0) by server.baldwin.cx (8.14.2/8.14.2) with ESMTP id m8ILbnge020803; Thu, 18 Sep 2008 17:37:49 -0400 (EDT) (envelope-from jhb@freebsd.org) From: John Baldwin To: freebsd-hackers@freebsd.org, stevefranks@ieee.org Date: Thu, 18 Sep 2008 14:44:26 -0400 User-Agent: KMail/1.9.7 References: <539c60b90809181041n658d2823y89e42bb0ccfa6d06@mail.gmail.com> In-Reply-To: <539c60b90809181041n658d2823y89e42bb0ccfa6d06@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200809181444.26895.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (server.baldwin.cx [IPv6:::1]); Thu, 18 Sep 2008 17:37:49 -0400 (EDT) X-Virus-Scanned: ClamAV 0.93.1/8282/Thu Sep 18 14:21:01 2008 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.5 required=4.2 tests=AWL,BAYES_00,NO_RELAYS autolearn=ham version=3.1.3 X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on server.baldwin.cx Cc: Subject: Re: proper types for printf()-ing pointers on amd64 that won't break i386? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Sep 2008 21:37:56 -0000 On Thursday 18 September 2008 01:41:42 pm Steve Franks wrote: > Hi, > > I'm trying to correct some warnings in a port marked > ONLY_FOR_ARCHS=i386. They stem from casting a pointer (which I assume > is a 64-bit unsigned) to "unsigned int" which is apparently 32 bits? > I sort of thought int was supposed to be the atomic register size, but > no doubt that would break more than it would help, so it's 32-bits. > Anyways, what's the right way to fix this? The port actually works > fine as-is on amd64, so I can only assume something was fixed for 7.1, > or someone was being extra cautious with the i386 tag. > > The code: > > typedef unsigned int cardinal; > ... > fprintf(stderr, "Mode Table Offset: $C0000 + $%x\n", > ((cardinal)map->mode_table) - ((cardinal)map->bios_ptr)); > > Can I just ditch the cast+%x and use %p? I don't have an i386 system > to test on, and I don't want to break anything if I submit a patch... If mode_table and bios_ptr are pointers, then their difference is not a pointer, but a ptrdiff_t. You can use %tx to print one of those in hex. Note, however, that subtracting pointers only works if they are of the same type, and it will return different results in this case unless they are char * pointers. Probably better is to do something like this: fprintf(stderr, "Mode Table Offset: $C0000 + $%x\n", (int)((uintptr_t)map->mode_table - (uintptr_t)map->bios_ptr)); Note that %p will include a '0x' prefix for non-NULL pointers which you probably don't want. -- John Baldwin