From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 089AE1A1E0B for ; Tue, 27 Sep 2016 13:27:19 -0700 (PDT) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP; 27 Sep 2016 13:27:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,406,1470726000"; d="scan'208";a="173846394" Received: from orsmsx104.amr.corp.intel.com ([10.22.225.131]) by fmsmga004.fm.intel.com with ESMTP; 27 Sep 2016 13:27:19 -0700 Received: from orsmsx116.amr.corp.intel.com (10.22.240.14) by ORSMSX104.amr.corp.intel.com (10.22.225.131) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 27 Sep 2016 13:27:18 -0700 Received: from orsmsx113.amr.corp.intel.com ([169.254.9.161]) by ORSMSX116.amr.corp.intel.com ([10.22.240.14]) with mapi id 14.03.0248.002; Tue, 27 Sep 2016 13:27:17 -0700 From: "Kinney, Michael D" To: "Brian J. Johnson" , Andrew Fish , Eugene Cohen , "Kinney, Michael D" CC: Alexei Fedorov , "edk2-devel@lists.01.org" , Laszlo Ersek Thread-Topic: [edk2] What is the right way to print a UINTN? Thread-Index: AdIX/FZUkJ+/GDfSRZe7u7ShyrQtxgASWdEAACvtKYAABDdLAAADQGEAAAGJsAAAAPOjgAAIdU6g Date: Tue, 27 Sep 2016 20:27:17 +0000 Message-ID: References: <0de4dd03-faa7-1608-9625-369ab5d6e682@redhat.com> <334067f6-b7b6-9fe4-02c6-f8af21982780@sgi.com> In-Reply-To: <334067f6-b7b6-9fe4-02c6-f8af21982780@sgi.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_IC x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiM2EyNjA1NTktYTQzMS00ODQzLWI0NTYtODEyNjZhN2UyMmI4IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6ImxyQVkrN0p2WUhJM2pxY0ZlQ01XRnU1bzJHUzZtdVwvSzFtWmlIbTg5RjJrPSJ9 x-originating-ip: [10.22.254.140] MIME-Version: 1.0 Subject: Re: What is the right way to print a UINTN? X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Sep 2016 20:27:19 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Brian, This is a good idea. I will have to study it some more=20 to figure out what the EBC versions of these macros would map to. Mike > -----Original Message----- > From: Brian J. Johnson [mailto:bjohnson@sgi.com] > Sent: Tuesday, September 27, 2016 10:14 AM > To: Andrew Fish ; Eugene Cohen > Cc: Kinney, Michael D ; Alexei Fedorov > ; edk2-devel@lists.01.org ; Laszlo > Ersek > Subject: Re: [edk2] What is the right way to print a UINTN? >=20 > On 09/27/2016 11:47 AM, Andrew Fish wrote: > > > >> On Sep 27, 2016, at 9:03 AM, Cohen, Eugene wrote: > >> > >>> Printing UINTN with %x *or* with %d are equally bugs. > >>> > >>> For X64 / AARCH64 / IA64 builds, they are actual bugs (that happen to > >>> work most of the time). > >> > >> Feel free to file a Bugzilla on the extensive usage of this in > >> edk2 [ducking and running]. :) > >> > >>>> I'm envisioning having to create a slide in the future for UEFI > >>>> training about the proper use of UINTNs and describing "If you think > >>>> it may exceed 2^32-1 then upcast to UINT64, otherwise don't worry > >>>> about it" and it makes me squirm. > >>> > >>> It makes me squirm too. I think the slide should recommend the > >>> casting > >>> that I proposed. ;) "There is no conversion specifier dedicated to > >>> UINTN; the portable way to print it is to cast it to UINT64, then pri= nt > >>> it with %Lx." > >> > >> This is reasonable although I expect to get asked why a lot of the > >> other code doesn't adhere to this recommendation. > >> > > > > I think this is a historical artifact. The older version of %x in > > the EDK (and early edk2) implied UINTN. We hit an issue with C > > integer math resulting in an int and that seemed to bork some > > toolchains. That is when things changed from UINTN to int. I guess > > the cleanup was practical vs. pedantic. >=20 > Thanks for the historical context, Andrew. It's interesting to hear, > if very unfortunate. >=20 > I've written code in the past which uses a #defined value for the > UINTN format character as a way to work around this issue without > casting everything to 64 bits. Something like: >=20 > // Format string for a naturally-sized unsigned integer > #if defined (MDE_CPU_IA32) > #define UINTN_FMT "0x%08x" > #elif defined (MDE_CPU_X64) > #define UINTN_FMT "0x%016lx" > #elif ... > ... > #endif >=20 > UINTN Val; > Val =3D Foo (); > DEBUG((DEBUG_INFO, "Value is " UINTN_FMT "\n", Val)); >=20 >=20 > I guess it's a matter of opinion if that's preferable to adding casts; > in my particular situation, I had to print values with that particular > format string in a lot of places, so it was convenient to #define it > once. >=20 > > > > Thanks, > > > > Andrew Fish > > > >> Thanks, > >> > >> Eugene > >> _______________________________________________ > >> edk2-devel mailing list > >> edk2-devel@lists.01.org > >> https://lists.01.org/mailman/listinfo/edk2-devel > > > > _______________________________________________ > > edk2-devel mailing list > > edk2-devel@lists.01.org > > https://lists.01.org/mailman/listinfo/edk2-devel > > >=20 >=20 > -- >=20 > Brian J. Johnson >=20 > -------------------------------------------------------------------- >=20 > My statements are my own, are not authorized by SGI, and do not > necessarily represent SGI's positions.