From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1MTo6p-0004kW-LE for mharc-grub-devel@gnu.org; Wed, 22 Jul 2009 22:32:39 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MTo6o-0004kQ-5b for grub-devel@gnu.org; Wed, 22 Jul 2009 22:32:38 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MTo6j-0004is-IB for grub-devel@gnu.org; Wed, 22 Jul 2009 22:32:37 -0400 Received: from [199.232.76.173] (port=46279 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MTo6j-0004if-Eu for grub-devel@gnu.org; Wed, 22 Jul 2009 22:32:33 -0400 Received: from c60.cesmail.net ([216.154.195.49]:3232) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.60) (envelope-from ) id 1MTo6i-0004zM-S6 for grub-devel@gnu.org; Wed, 22 Jul 2009 22:32:33 -0400 Received: from unknown (HELO smtprelay2.cesmail.net) ([192.168.1.112]) by c60.cesmail.net with ESMTP; 22 Jul 2009 22:32:30 -0400 Received: from [192.168.1.151] (c-69-141-194-35.hsd1.pa.comcast.net [69.141.194.35]) by smtprelay2.cesmail.net (Postfix) with ESMTPSA id 9549A34C6A for ; Wed, 22 Jul 2009 22:43:06 -0400 (EDT) From: Pavel Roskin To: The development of GRUB 2 In-Reply-To: <1248314598.4660.41.camel@accesodirecto.casa> References: <1248289850.10302.57.camel@accesodirecto.casa> <1248311335.14755.26.camel@ct> <1248314598.4660.41.camel@accesodirecto.casa> Content-Type: text/plain; charset="ISO-8859-1" Date: Wed, 22 Jul 2009 22:31:48 -0400 Message-Id: <1248316308.14755.40.camel@ct> Mime-Version: 1.0 X-Mailer: Evolution 2.26.3 (2.26.3-1.fc11) Content-Transfer-Encoding: 8bit X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: Re: [RFC,PATCH] C99 format specifiers for fixed-length integer types X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jul 2009 02:32:38 -0000 On Thu, 2009-07-23 at 04:03 +0200, Javier Martín wrote: > El mié, 22-07-2009 a las 21:08 -0400, Pavel Roskin escribió: > > I doubt about "runtime weirdness". gcc is good at catching such > > problems at the compile time. > Yes, in naked expressions. However, once we start using casts the C > compiler tends to be quite silent about the whole nitty-gritty process. > For example, the following code generates no warnings (with -ansi > -pedantic -Wall -Wconversion): > > unsigned short a = (unsigned short) 123456789; > uint16_t b = (uint16_t) UINT32_C(123456789); > > That is, casts shut the compiler up (without the casts gcc just shows a > warning about the truncation being performed). The runtime value of both > a and b is 0xcd15 in my x86_64 Linux box. That's totally expected. But it doesn't represent a full scenario when something can go wrong when porting to another platform. > > It would be a good idea to use standard modifiers if they were not so > > hard on the eye. > Well, I suggested GRUB_x names for the macros, where x is the C99 > standard name, but we could use them directly as PRIx64 and the like. > About verbosity, though... Have you programmed in Java? Some appearances > of GRUB_PRId32 are nothing compared to System.out.println or > java.util.ArrayList, yet I write the last two religiously. We are not writing GRUB in Java. I guess Java also offers way to simplify code and to check its correctness that we don't have in C. > > That's a biased example where the size of the arguments is obvious. And > > even then, it's hard to read. And if you put GRUB_PRI32o instead of > > GRUB_PRI16o there, the compiler won't tell you anything. > Hey, I'm the one proposing the patch. Surely you wouldn't expect me to > be unbiased ;) > Nevertheless, the issue you pointed happens because variadic arguments > are automatically promoted with the following rules [1][2] from the > ancient days of C: > - Integral types narrower than "int" -> int > - Floating point types narrower than "double" -> double > So, you could argue, we could do without at the very least PRI?8 (and, > here in grub, PRI?16 too). However, given how obscure this "feature" is > (see [1]), I'd go for keeping all of them: orthogonality means less > surprises for the future coders. That's OK. > > The patch includes the easy part, namely adding the macros. But I > > doesn't think it would be so pretty with the ugly part, that is, > > "fixing" every almost every *printf call. It will be very hard to > > review. > Well, of course. This patch only adds the infrastructure, or else it > would be too invasive. Once it is in, a small number of people can start > checking most source files and replace the old specifiers when > appropriate. And that's what I don't want to see. We sacrifice readability and go through massive code changes. We only gain potential fixes for ports to hypothetical platforms. In my opinion, it's not worth the trouble. I'm not going to spend any more time on this. If you convince any maintainers, fine. -- Regards, Pavel Roskin