Date: Mon, 24 Mar 2025 16:59:20 +0100 From: Olivier Certner <olce@freebsd.org> To: Konstantin Belousov <kib@freebsd.org>, Ronald Klop <ronald-lists@klop.ws> Cc: dev-commits-src-all@freebsd.org, src-committers@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: c18a16ebcf5b - main - kern_proc_kqueues_out(): maxlen == -1 means there is no maxlen Message-ID: <8229058.iDzAj6rjnq@ravel> In-Reply-To: <1305725331.9507.1742828788168@localhost> References: <202503240454.52O4s0Xi051381@gitrepo.freebsd.org> <1305725331.9507.1742828788168@localhost>
index | next in thread | previous in thread | raw e-mail
[-- Attachment #1 --] Hi, > (snip) > > + if (maxlen == -1 || maxlen == 0) > As maxlen is of the unsigned type size_t, how can it be -1? > Or am I mistaken on this? It's of course true that 'maxlen' can't be -1 mathematically as it has an unsigned type, but that's not what 'maxlen == -1' tests. In this example, 'maxlen' is an unsigned type of size at least equal to 'unsigned int', whose values cannot all be represented in a signed 'int' (well, that last part is true but not the real reason, which has to do with integer ranks). According to the standard promotion rules, and because -1 as an integer constant is interpreted as of type 'int', both arguments of '==' will be converted to 'unsigned int', and conversion of a signed type to an unsigned one is done by computing its congruence to the number of values the latter can represent (this is the mathematical description; with two-complement representation, that's basically just truncating the bits that are "too high", or sign-extending if the unsigned type destination is wider, and in this precise case, just keeping the same exact representation bits). So, basically, this test is equivalent to 'maxlen == UINT_MAX' on 32-bit machines or 'maxlen == ULONG_MAX' on 64-bit ones. Relevant C standard passages are, in section Language > Conversions > Arithmetic operands, the "Boolean, characters, and integers", "Signed and unsigned integers" and "Usual arithmetic conversions" chapters, and, under Language > Expressions, the chapter about equality operators (in particular, the fact that it states that the usual arithmetic conversions apply), and chapter Language > Lexical elements > Constants > Integer constants. Regards. -- Olivier Certner [-- Attachment #2 --] -----BEGIN PGP SIGNATURE----- iQIzBAABCQAdFiEEmNCxHjkosai0LYIujKEwQJceJicFAmfhgVgACgkQjKEwQJce JicMug/8DXuApknJ9/MpLLBj6QZ3TICmietYFg3OYjHGVkluxu9nmRoSDlre3Het d/9csBgriOiW8MJHgkq9FiJsmq6kwvLdh3cEeUjcdwGWdqapY7+gm5h1K3I9Pm3O hW3dJne9lJL1aSlbz189QdA70aCf3+Mu91d1pVGVtzctXman7nkDUI1l6JTri3hu 0VOD/FsirlOt6JWSyVGuYRbMRCR7ViaGks9ahjo9aRyV1wCmUCaysG1JevvYyDLh o14vECCOPZltsuDA8XbV9uDjCon4KR0wTL2nFNwAPTI0DnobQ8Y2ntGcuJdBP1p0 r0ZWNjFrCOsxutpep2N6ODaiIhXMrKcsD6VPgSLcOcd4oCYvf60EgkCQiE5HG+HQ 7JrLfVvldqo4oXNJtzlXRTe8ODZ37gd6mFZtiJ611fA9pZ23ZFWy4aQ/1iWLyFEN S7lvBo9Pbyi/qhD8SHvMDrZraP3DpD+HDzJDmoAs5Z4MtGO02YSX7eZ6LLeoq4Pw /y7rrj/AdyDfAopseR5go0tPr3Mw1ToRH8HPsL0igluKuQ8vX/6lcve97Z4K+6D1 IFFooTh7OvCjb/R5o0w2ScNJsuKBBeHafadd2I7zg1Z5ih7QD8PHQCiKhKByOF+4 nG/gaSrGiqsmOkSfKSUbfJrmLFX7aOf7oF6rmvZeZEuvRLg3qVs= =V36y -----END PGP SIGNATURE-----help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?8229058.iDzAj6rjnq>
