From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1MTneX-00008I-SP for mharc-grub-devel@gnu.org; Wed, 22 Jul 2009 22:03:25 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MTneW-00008C-UT for grub-devel@gnu.org; Wed, 22 Jul 2009 22:03:24 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MTneW-00007y-Al for grub-devel@gnu.org; Wed, 22 Jul 2009 22:03:24 -0400 Received: from [199.232.76.173] (port=52039 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MTneW-00007v-7K for grub-devel@gnu.org; Wed, 22 Jul 2009 22:03:24 -0400 Received: from ey-out-1920.google.com ([74.125.78.150]:20636) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MTneV-00015v-GK for grub-devel@gnu.org; Wed, 22 Jul 2009 22:03:23 -0400 Received: by ey-out-1920.google.com with SMTP id 5so193884eyb.24 for ; Wed, 22 Jul 2009 19:03:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:in-reply-to :references:content-type:date:message-id:mime-version:x-mailer; bh=zgyLswvUg1+AZA6ShoUj/z+P/N0/znA3xljTXA+Vuqk=; b=SlUeaCKTrJoR3j0TqRzglAJ33l84aMX5LdV2nQdBIngJS2djuXeT2nF0+rBssDppp8 YxMtv0wMaHYA9Udv5b4qIvleiOaVvu0ORK3BpCAgm6oeEyyvrjcPgLeET3SwpW/xT54G xSlBvpIFLyU14nuCl443xzmTcili0otZm7lBA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:in-reply-to:references:content-type:date:message-id :mime-version:x-mailer; b=iiGjXkxGp8Qt0KMPYafF9XmCRf0stSWNKyxw0AIMfNOsqcxK9nKyh/rotjxubBUpH/ ZpEUjlfRmmsLSG5TRKxSN5XSI44UT21wDamOYnr+D0QxbVeyQmWfxn9MqSdZp42M9VVr kyCkww6aBPzuJGwjXAHyg25SI9RryweUQARqI= Received: by 10.210.57.3 with SMTP id f3mr7402374eba.94.1248314601405; Wed, 22 Jul 2009 19:03:21 -0700 (PDT) Received: from ?192.168.1.100? (89.141.11.145.dyn.user.ono.com [89.141.11.145]) by mx.google.com with ESMTPS id 7sm894142eyg.36.2009.07.22.19.03.20 (version=SSLv3 cipher=RC4-MD5); Wed, 22 Jul 2009 19:03:20 -0700 (PDT) From: Javier =?ISO-8859-1?Q?Mart=EDn?= To: The development of GRUB 2 In-Reply-To: <1248311335.14755.26.camel@ct> References: <1248289850.10302.57.camel@accesodirecto.casa> <1248311335.14755.26.camel@ct> Content-Type: multipart/signed; micalg="pgp-sha1"; protocol="application/pgp-signature"; boundary="=-kVOxpiZZkgdT1YFCI+by" Date: Thu, 23 Jul 2009 04:03:18 +0200 Message-Id: <1248314598.4660.41.camel@accesodirecto.casa> Mime-Version: 1.0 X-Mailer: Evolution 2.26.1 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) 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:03:25 -0000 --=-kVOxpiZZkgdT1YFCI+by Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable El mi=C3=A9, 22-07-2009 a las 21:08 -0400, Pavel Roskin escribi=C3=B3: > 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 =3D (unsigned short) 123456789; uint16_t b =3D (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. > 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. > 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. >=20 > 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. >=20 > > -#if GRUB_CPU_SIZEOF_VOID_P =3D=3D 8 > > +#if GRUB_CPU_SIZEOF_LONG =3D=3D 8 >=20 > This belongs to a separate patch. Oops, sorry. It seems I had a little mixup between the trunk files and Bean's lib branch. I might post this change as a separate patch indeed. [1] I would point at section 6.5.2.2.6 (function calls, automatic argument promotions) of the C99 standard, but I really do not understand that paragraph quite well. [2] Here it says so with more certainty, but they seem to be class notes http://www.eumus.edu.uy/eme/c/c-notes_summit/intermediate/sx11.html#sx11c --=20 -- Lazy, Oblivious, Recurrent Disaster -- Habbit --=-kVOxpiZZkgdT1YFCI+by Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Esto es una parte de mensaje firmado digitalmente -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iQIcBAABAgAGBQJKZ8TgAAoJEKSl+Fbdeo72CH4QAIliCdYr+ZtlfwPbw05C0C8N nnxwfZTp4zsv/5rofyJTsligxVsu6omB6achB9WFnXKwncNZ1hqrD9zQFvKK5BLC wwInwmL/yoFFpOV/BEZ5gP7Acax+RLqWxQZg3rlDRjEBodfIw72KIVHd0Pt4C5f1 O/TlWF94xrnEmnuB8orfNXf/UQ7kCsvvikkzBJtVtYHMUOAXA0wjTXSMgodXUKaN TK66ZNX38zShnI5/zxzMIXIGLIuvRucHTw8u0g0Mf4JDBTnLQDhA7hVjfhkuJX24 YIpT8HekcbvDzJPi8Feip2nThArTyxYM27vyeHFCQK3LrJUXAxE6oXRvTfpI53am 0eYj0rRWOkC+6jNVDj7norrpkEpSeoNj5BvxKspeE93ZrdyFgIBhN0JVjauvKncD hwf2IPTYvnr2vzdLAfkC946dYCsaP2r/H7YF4Jyjdg0UlbGS1LSOzao0UuLbhnvB CSmNWJ+VD2DQAZHyGB60BGhF5hKLdVqNcsY6hi35g/fIje/m/rDwc8+z9fEZEDFE 8o7TVTGp3iLuEECXyWyxIGzCbK0NjcsJuF9IGyCrcr0cMk6XH58fHgjuD3AmPsdQ XTYhy43qtslyIyZnB8teFXxFzj68usR/SWnwxIuTl1G4Q0VqASUkhPD+Pczq0WWN yJASry4bDia/cb41pLzy =iFJy -----END PGP SIGNATURE----- --=-kVOxpiZZkgdT1YFCI+by--