From owner-freebsd-hackers@FreeBSD.ORG Thu Sep 18 18:45:45 2008 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2CF51106567B for ; Thu, 18 Sep 2008 18:45:45 +0000 (UTC) (envelope-from lgusenet@be-well.ilk.org) Received: from be-well.ilk.org (dsl092-078-145.bos1.dsl.speakeasy.net [66.92.78.145]) by mx1.freebsd.org (Postfix) with ESMTP id E7DC98FC1A for ; Thu, 18 Sep 2008 18:45:44 +0000 (UTC) (envelope-from lgusenet@be-well.ilk.org) Received: by be-well.ilk.org (Postfix, from userid 1147) id 5D9E828444; Thu, 18 Sep 2008 14:26:59 -0400 (EDT) To: stevefranks@ieee.org References: <539c60b90809181041n658d2823y89e42bb0ccfa6d06@mail.gmail.com> From: Lowell Gilbert Date: Thu, 18 Sep 2008 14:26:59 -0400 In-Reply-To: <539c60b90809181041n658d2823y89e42bb0ccfa6d06@mail.gmail.com> (Steve Franks's message of "Thu\, 18 Sep 2008 10\:41\:42 -0700") Message-ID: <448wtpb98s.fsf@be-well.ilk.org> User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailman-Approved-At: Thu, 18 Sep 2008 18:50:10 +0000 Cc: hackers@freebsd.org Subject: Re: proper types for printf()-ing pointers on amd64 that won't break 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 18:45:45 -0000 "Steve Franks" writes: > 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... What is actually being printed isn't a pointer, but the difference between two pointers (I assume from your comments; the code included isn't enough to show where they come from). That means the correct type of what's being printed is size_t, which our printf seems to support with a "z" modifier. Removing the explicit casts or (if necessary), replacing them with something that is big enough will also be needed.