From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-in4.apple.com (mail-out4.apple.com [17.151.62.26]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 112901A1E0B for ; Tue, 27 Sep 2016 10:46:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; d=apple.com; s=mailout2048s; c=relaxed/simple; q=dns/txt; i=@apple.com; t=1474998417; x=2338912017; h=From:Sender:Reply-To:Subject:Date:Message-id:To:Cc:MIME-version:Content-type: Content-transfer-encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-reply-to:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=JZ4i+/THXGZ/wwUdExf2I4c7fFwSttsxaFWheXZ04lc=; b=bulYUqJ9H9+kH+LcEN7z7cxCPlK3NUvEuw+57f7C1baLsyvRUpawrN8Fx2iaXgng NJL/qNVGJKLfUwGjsH8L8uUe9/eOjkfLtlY0kkyAFpi2Xsyihcr3ryZn0VCbvcy5 YNQ9KpVWO4GMwWS2pBvFEGkj5ZDl9vtuhpquDv+tXgTupnfvCNKt+O2oJiiHJBqA l+RjqMmd40OvgKbGDYO7hyuVLeZATcT03vwTfdsnHkldybZ0zwZa22jShpy9J4GL qQGVo1H9RYItknYeCJC5Jl+WBw/fyCYbieJdTTJhtpWlJIntdQrb03oZgwtYfzcK m6uFQau/5AmSv3K9OTxNuQ==; Received: from relay5.apple.com (relay5.apple.com [17.128.113.88]) by mail-in4.apple.com (Apple Secure Mail Relay) with SMTP id 44.4F.07433.190BAE75; Tue, 27 Sep 2016 10:46:57 -0700 (PDT) X-AuditID: 11973e12-f79b16d000001d09-ec-57eab09114ff Received: from nwk-mmpp-sz11.apple.com (nwk-mmpp-sz11.apple.com [17.128.115.155]) by relay5.apple.com (Apple SCV relay) with SMTP id 20.86.27929.190BAE75; Tue, 27 Sep 2016 10:46:57 -0700 (PDT) MIME-version: 1.0 Received: from da0601a-dhcp143.apple.com ([17.226.15.143]) by nwk-mmpp-sz11.apple.com (Oracle Communications Messaging Server 8.0.1.1.0 64bit (built Jun 15 2016)) with ESMTPSA id <0OE600DT3C297X10@nwk-mmpp-sz11.apple.com>; Tue, 27 Sep 2016 10:46:57 -0700 (PDT) Sender: afish@apple.com From: Andrew Fish In-reply-to: Date: Tue, 27 Sep 2016 10:46:56 -0700 Cc: Eugene Cohen , Alexei Fedorov , "edk2-devel@lists.01.org" , Laszlo Ersek Message-id: References: <0de4dd03-faa7-1608-9625-369ab5d6e682@redhat.com> To: Mike Kinney X-Mailer: Apple Mail (2.3226) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrMLMWRmVeSWpSXmKPExsUi2FAYoTtxw6twg3WzlSwOP4uxWLfnG7tF 6+c3TBbLju1gsejo+MfkwOqxZt4aRo9d23YyeSze85LJY9KFx8we7/ddZQtgjeKySUnNySxL LdK3S+DKeLW+h6ngm2xF44RJzA2M88S7GDk5JARMJM6s62CFsMUkLtxbz9bFyMUhJLCXUeLS lS/MMEU9dy4yQiQOMUq82fyHBSTBKyAo8WPyPSCbg4NZQF7i4HlZkDCzgJbE90etLBD1PUwS HS9+gg0SFhCXeHdmE5RtLbF45kewzWwCyhIr5n9gB7E5BcIkpjdfZwSxWQRUJdb1v2WBGLqY UWLq1xqIvTYSHbv+MUMseMkssXD3fWaQI0QEdCS6V0aDmBICshKzf3mBlEgI3GeT2HP2KMsE RpFZSM6ehXD2LCRnL2BkXsUolJuYmaObmWeil1hQkJOql5yfu4kRFCvT7YR2MJ5aZXWIUYCD UYmHl6HoVbgQa2JZcWXuIUZpDhYlcd7P1U/DhQTSE0tSs1NTC1KL4otKc1KLDzEycXBKNTDa fV/yasaErfnHfRKnTb57/H/tu40Li4zmu85dXLwmtWNuwtYUMVnR/A17V/z5wxy1PFF45bEi 2VfR91Pbnwqtqp1ssESdIfJ9E/tG7U9/+HeXh7paP1uo3vD0s7T7G8EG08yT+6TtWCqFH5+c mL0qaauocesywcB7zmzuvyWYHY/8jviwLu+XEktxRqKhFnNRcSIA8y/5k3YCAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprHIsWRmVeSWpSXmKPExsUi2FA8W3fihlfhBnMmi1scfhZjsW7PN3aL 1s9vmCyWHdvBYtHR8Y/JgdVjzbw1jB67tu1k8li85yWTx6QLj5k93u+7yhbAGsVlk5Kak1mW WqRvl8CV8Wp9D1PBN9mKxgmTmBsY54l3MXJySAiYSPTcucgIYYtJXLi3nq2LkYtDSOAQo8Sb zX9YQBK8AoISPybfA7I5OJgF5CUOnpcFCTMLaEl8f9TKAlHfwyTR8eInM0hCWEBc4t2ZTVC2 tcTimR9ZQWw2AWWJFfM/sIPYnAJhEtObr4MtZhFQlVjX/5YFYuhiRompX2sg9tpIdOz6xwyx 4CWzxMLd95lBjhAR0JHoXhkNYkoIyErM/uU1gVFwFpJLZyFcOgvJpQsYmVcxChSl5iRWmuol FhTkpOol5+duYgSHdmHEDsb/y6wOMQpwMCrx8DIUvQoXYk0sK67MBQYFB7OSCO/x1UAh3pTE yqrUovz4otKc1OJDjMlA509klhJNzgfGXV5JvKGJiYGJsbGZsbG5iTlpwkrivOt4H4QLCaQn lqRmp6YWpBbBbGHi4JRqYLwTWyxyaPIBIbmc1+efxT5wWyk5If70u98bAn0m6ippcapotCxt ZdQV+jJPS+Dzyzu1z/Y/vxTMx8r41MpG7MpPG8d34tcXx/LGzb77UWBZtN+WGZ5h095mH9kW oRDGNXEXh7TgGrmiJ0s8rc7NyqxMW5a2eO4/04VyFfu37Dr6pT9FbvlaZiUlluKMREMt5qLi RAAMhC+VsQIAAA== 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 17:46:58 -0000 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII > On Sep 27, 2016, at 10:27 AM, Kinney, Michael D wrote: > > Andrew, > > Here is the comment in current code that explains some of the why. > > case 'd': > if ((Flags & LONG_TYPE) == 0) { > // > // 'd', 'u', 'x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int". > // This assumption is made so the format string definition is compatible with the ANSI C > // Specification for formatted strings. It is recommended that the Base Types be used > // everywhere, but in this one case, compliance with ANSI C is more important, and > // provides an implementation that is compatible with that largest possible set of CPU > // architectures. This is why the type "int" is used in this one case. > // > > If code uses type UINTN or INTN, then the max value that can be used > for portable sources is max value for the CPU arch with the smallest > UINTN width. For the CPU archs in UEFI/PI specs today, the smallest UINTN > width is 32-bits. > > Portable sources that use type UINTN must never use values larger than > 32-bits. Same for type INTN. Only use values in signed 32-bit range. > > It is possible for 64-bit specific sources to use type UINTN with values > larger than 32-bits, but those sources would not be portable and would > need to be changed to UINT64 to be portable. Is this the case that are > really discussing here? > If you have a UINTN that can only represent 32-bits is that not a UINT32 :). Thanks, Andrew Fish > Thanks, > > Mike > > >> -----Original Message----- >> From: afish@apple.com [mailto:afish@apple.com] >> Sent: Tuesday, September 27, 2016 9:47 AM >> To: Eugene Cohen >> Cc: Laszlo Ersek ; Kinney, Michael D ; >> Alexei Fedorov ; edk2-devel@lists.01.org > devel@ml01.01.org> >> Subject: Re: [edk2] What is the right way to print a UINTN? >> >> >>> 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 print >>>> 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. >> >> 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