From: Laszlo Ersek <lersek@redhat.com>
To: "Cohen, Eugene" <eugene@hp.com>
Cc: "Kinney, Michael D" <michael.d.kinney@intel.com>,
Alexei Fedorov <Alexei.Fedorov@arm.com>,
"edk2-devel@lists.01.org" <edk2-devel@ml01.01.org>
Subject: Re: What is the right way to print a UINTN?
Date: Tue, 27 Sep 2016 18:31:21 +0200 [thread overview]
Message-ID: <4fd335cf-31c6-5943-ead7-ccbd4c8d0787@redhat.com> (raw)
In-Reply-To: <AT5PR84MB0291E06299E5F9C0C3016AA8B4CC0@AT5PR84MB0291.NAMPRD84.PROD.OUTLOOK.COM>
On 09/27/16 18:03, 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]. :)
Not a bad idea, but it's not practical. I take care to use the right
casts and conversion specifiers whenever I write new code, but for
identifying existent incorrect calls, compiler support would be necessary.
I guess we could add the GCC function attribute that I mentioned earlier
to some of the PrintLib functions, and then address the resultant
warning messages. The problem is that some of the edk2-defined
conversion specifiers
- are not defined in standard (or GNU) C -- for example, %t --, which
might prevent GCC from pairing the corresponding argument with any
conversion specifier at all,
- and/or work differently from their standard (or GNU) C counterparts:
- for example %g is entirely different between edk2 and standard C
((EFI_GUID *) vs. double),
- the "L" length modifier is invalid for %x in standard C,
- etc.
If someone is into GCC or CLANG plugin development, creating an "edk2
PrintLib" function attribute could be a good task :)
>>> 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.
"Because people didn't realize it was a bug and it worked in practice"? :)
Thanks
Laszlo
next prev parent reply other threads:[~2016-09-27 16:31 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-26 13:46 What is the right way to print a UINTN? Cohen, Eugene
2016-09-26 14:39 ` Alexei Fedorov
2016-09-26 15:31 ` Laszlo Ersek
2016-09-27 12:29 ` Cohen, Eugene
2016-09-27 14:30 ` Laszlo Ersek
2016-09-27 16:03 ` Cohen, Eugene
2016-09-27 16:31 ` Laszlo Ersek [this message]
2016-09-27 16:47 ` Andrew Fish
2016-09-27 17:14 ` Brian J. Johnson
2016-09-27 18:31 ` Laszlo Ersek
2016-09-27 20:27 ` Kinney, Michael D
2016-09-27 17:27 ` Kinney, Michael D
2016-09-27 17:46 ` Andrew Fish
2016-09-27 18:20 ` Kinney, Michael D
2016-09-27 19:28 ` Cohen, Eugene
2016-09-27 20:10 ` Kinney, Michael D
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4fd335cf-31c6-5943-ead7-ccbd4c8d0787@redhat.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox