Date: Tue, 2 May 2017 21:51:49 +1000 (EST) From: Bruce Evans <brde@optusnet.com.au> To: Konstantin Belousov <kostikbel@gmail.com> Cc: Hans Petter Selasky <hps@selasky.org>, Bruce Evans <brde@optusnet.com.au>, Alan Somers <asomers@freebsd.org>, Gleb Smirnoff <glebius@freebsd.org>, "src-committers@freebsd.org" <src-committers@freebsd.org>, "svn-src-all@freebsd.org" <svn-src-all@freebsd.org>, "svn-src-head@freebsd.org" <svn-src-head@freebsd.org> Subject: Re: svn commit: r317061 - in head: libexec/rpc.rstatd sys/amd64/amd64 sys/amd64/include sys/arm/arm sys/arm/include sys/arm64/include sys/cddl/contrib/opensolaris/uts/common/fs/zfs sys/compat/linprocfs... Message-ID: <20170502212549.Y1176@besplex.bde.org> In-Reply-To: <20170502102932.GC1622@kib.kiev.ua> References: <201704171734.v3HHYlf5022945@repo.freebsd.org> <CAOtMX2jdNj0du0ZuUKPr16iHK_YeNVzf-nDvwC-MuFM003VVAg@mail.gmail.com> <20170419130428.J956@besplex.bde.org> <20170430201324.GV1622@kib.kiev.ua> <20170501163725.U972@besplex.bde.org> <20170502095527.GB1622@kib.kiev.ua> <27c9a2b4-b993-2370-1da8-b4beef354a1b@selasky.org> <20170502102932.GC1622@kib.kiev.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 2 May 2017, Konstantin Belousov wrote: > On Tue, May 02, 2017 at 12:02:32PM +0200, Hans Petter Selasky wrote: >> On 05/02/17 11:55, Konstantin Belousov wrote: >>> + out1 = 0xffffffff; >> >> Nitpicking: >> >> Should this be written: 0xffffffffU ?? No, 0xffffffffU should be written 0xffffffff except in very delicate code which needs it to have type precisely u_int (and u_int has at least 32 bits, else the constant would still not be u_int). > Compiler must do it on its own. The constant is not representable as > int so it is auto-promoted to unsigned int, if fitting. It doesn't really matter here, but we must make too many assumptions and do too many type analyses to see that it doesn't matter (or too see that either 0xffffffff or 0xffffffffU is correct or needed, but plain 0xffffffff usually works better since it lets the compiler decide). Here you assume <= 32-bit ints for simplicity (otherwise, 0xffffffff would be int). POSIX and practice also requires >= 32-bit ints. So ints are assumed to be precisely 32 bits, and then 0xffffffff is just a better spelling of 0xffffffffU. Here we only need that the constant is non-negative. Its type is irrelevant, so it would be a style bug to force the type to unsigned or larger (with < 32-bit ints) using a U suffix. All integer constants are non-negative. We could even spell the constant in decimal here. It would then have type int64_t. Spelling it in hex makes its value clearer and allows its type to be unsigned. Bruce
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170502212549.Y1176>