linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Alejandro Colomar (man-pages)" <alx.manpages@gmail.com>
To: Martin Sebor <msebor@gmail.com>, LIU Hao <lh_mouse@126.com>,
	johnsfine@verizon.net,
	"gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>,
	"jg@jguk.org" <jg@jguk.org>
Cc: "linux-man@vger.kernel.org" <linux-man@vger.kernel.org>,
	"fw@deneb.enyo.de" <fw@deneb.enyo.de>,
	"mtk.manpages@gmail.com" <mtk.manpages@gmail.com>
Subject: Re: strlen
Date: Fri, 9 Jul 2021 22:19:51 +0200	[thread overview]
Message-ID: <ec778d25-c14e-021a-e057-bfa0d6c1dd99@gmail.com> (raw)
In-Reply-To: <8e0db7f8-bbdb-1dc1-b4ce-5f2da0bf1708@gmail.com>


On 7/9/21 7:26 PM, Martin Sebor wrote:
> On 7/8/21 8:08 PM, LIU Hao via Gcc-help wrote:
>> 在 7/8/21 8:05 PM, johnsfine--- via Gcc-help 写道:
>>>   This is not the forum for such a discussion.  But I want to make 
>>> people reading this aware that many expert C and C++ programmers 
>>> (likely a majority) consider that advice to avoid unsigned types to 
>>> be horrible advice.

I'm sorry if it's not the right place, I could remove the lists
from the CC if it's too noisy, but I think an important point is
here, and a couple of emails won't damage too much the mailing lists.

On the other hand, I consider bad etiquette removing CCs from
a discussion.

>>> I advise people to avoid signed types and I do so myself.  If an 
>>> integer value won't be negative, it shouldn't be signed.  That makes 
>>> your intent clearer to anyone reading your code, and (especially in 
>>> x86-64) lets the compiler generate smaller and faster code.

As others have showed with facts, and the Google style guide also hints,
using unsigned types just removes the opportunity of the compiler
to optimize on overflow, because it has to account for wrapping around.

>>
>> That makes no sense. Would you prefer unsigned integers to signed 
>> ones, for something that can only be one of {1,2,3,4}? Just because 
>> something can't be negative, does not mean it should be unsigned.
That.
The same way that because a number is never going to be
greater than 100 is it any better to use [u]int256_t.
Just use int, unless you have a reason not to.

Please John, read the paper from Bjarne about unsigned types,
it really covers a lot.  If you still disagree after reading that,
feel free to argument it.

<http://open-std.org/JTC1/SC22/WG21/docs/papers/2019/p1428r0.pdf>

> 
> There are benefits to making that explicit by choosing an unsigned
> type: the result of converting a narrower unsigned type to a wider
> unsigned type is unchanged.  The result of converting it to a wider
> signed type may change.  This has an impact on value range propagation
> which in turn can influence other optimizations as well as warnings.

That problem with implicit conversions to larger types is not a
problem of signed integers, not even a problem of unsigned integers.
It's a problem of mixing both.
If you use signed integers for everything, you won't have that problem.


Alex


-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

  reply	other threads:[~2021-07-09 20:19 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-04 18:01 strlen Jonny Grant
2020-09-04 19:21 ` strlen Florian Weimer
2020-09-04 23:14   ` strlen Jonny Grant
2020-09-05  7:12     ` strlen Florian Weimer
2021-07-06 20:30       ` strlen Jonny Grant
2021-07-06 22:11         ` strlen Florian Weimer
2021-07-07 11:36           ` strlen Jonny Grant
2021-07-07 12:22             ` strlen Alejandro Colomar (man-pages)
2021-07-07 12:31               ` strlen Alejandro Colomar (man-pages)
2021-07-07 13:31                 ` strlen Jonny Grant
2021-07-07 16:57                   ` strlen Alejandro Colomar (man-pages)
2021-07-07 17:23                     ` strlen Alejandro Colomar (man-pages)
2021-07-07 17:33                       ` strlen Alejandro Colomar (man-pages)
2021-07-09 13:48                         ` strlen Jonny Grant
2021-07-08 10:07                     ` strlen Jonny Grant
2021-07-08 11:06                       ` strlen Alejandro Colomar (man-pages)
2021-07-08 12:13                         ` strlen Xi Ruoyao
2021-07-08 23:49                         ` strlen Segher Boessenkool
2021-07-09 13:54                           ` strlen Jonny Grant
2021-07-09 14:17                             ` strlen Alejandro Colomar (man-pages)
2021-07-09 16:11                               ` strlen Xi Ruoyao
2021-07-10  1:00                               ` strlen Segher Boessenkool
2021-07-09 10:50                         ` strlen Jonny Grant
2021-07-09 11:27                           ` strlen Alejandro Colomar (man-pages)
2021-07-09 11:43                             ` strlen Alejandro Colomar (man-pages)
     [not found]                         ` <1627912755.3783669.1625745946723@mail.yahoo.com>
     [not found]                           ` <59a70222-a46f-1e65-c9db-6c9e577c8adc@126.com>
2021-07-09 17:26                             ` strlen Martin Sebor
2021-07-09 20:19                               ` Alejandro Colomar (man-pages) [this message]
2021-07-09 20:44                     ` strlen Jonny Grant
2021-07-10 18:37                       ` strlen Alejandro Colomar (man-pages)
2021-07-10 20:49                         ` strlen Jonny Grant
2021-07-10 21:36                           ` strlen Alejandro Colomar (man-pages)
2021-07-12 21:16                             ` strlen Jonny Grant

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-all 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=ec778d25-c14e-021a-e057-bfa0d6c1dd99@gmail.com \
    --to=alx.manpages@gmail.com \
    --cc=fw@deneb.enyo.de \
    --cc=gcc-help@gcc.gnu.org \
    --cc=jg@jguk.org \
    --cc=johnsfine@verizon.net \
    --cc=lh_mouse@126.com \
    --cc=linux-man@vger.kernel.org \
    --cc=msebor@gmail.com \
    --cc=mtk.manpages@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).