git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: eugenio gigante <giganteeugenio2@gmail.com>
To: git@vger.kernel.org
Subject: [GSoC] Use unsigned integral type for collection of bits
Date: Sun, 18 Feb 2024 12:36:57 +0100	[thread overview]
Message-ID: <CAFJh0PTiN18LcKP6LW0d1u2gkodBD2cOJRBzU_subBaFpzM=CA@mail.gmail.com> (raw)

Hi all,
I was looking around the codebase for some field of a structure that
stores collections of bits with signed int type.
I used this simple grep command to search for it:

$ grep -r -n "\tsigned int" .
> ./diffcore.h:63:     signed int is_binary : 2;

The struct in question is "diff_filespec" and Junio commented the
declaration of the field as following:

/* data should be considered "binary"; -1 means "don't know yet" */

So, if I understood it correctly, possible values are:
 1 -> 01
 2 -> 10
-1 -> 11
On the other, by changing it to unsigned values would be:
1 -> 01
2 -> 10
3 -> 11

I read somewhere that one should always prefer unsigned integral type over

signed integral type for a couple of reasons [1].

These involve operations like Modulus, Shifting and Overflow.

I didn't dig too much into how the field is used and if there are cases in which

the mentioned operations are involved (I would like the community
opinion about this topic before).


Moreover, I don’t know if such a change breaks too much code and if
it’s worth it.

Probably it's not that tragic since the header 'diffcore.h' is only
included in two other files,

but maybe I'm missing something. For sure, various If conditions used
by the function

'diff_filespec_is_binary' inside 'diff.c' would have to be changed.


Besides, it's possible that my grep command is not enough and maybe
more "signed int" can be spotted.

Thanks!
Eugenio Gigante.
P.S. I was insecure about how to send this email since it does not
include a commit.
I decide not to use git-send-email. Hoping I didn't mess up the format.

[1]
https://embeddedgurus.com/stack-overflow/2009/05/signed-versus-unsigned-integers/


             reply	other threads:[~2024-02-18 11:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-18 11:36 eugenio gigante [this message]
2024-02-18 19:09 ` [GSoC] Use unsigned integral type for collection of bits Eric Sunshine
     [not found]   ` <CAFJh0PTgjj=1QAYD+tyqc_35TZE78QJJv4WU-W3aiJiFOWHP=w@mail.gmail.com>
     [not found]     ` <CAFJh0PRJkVBr-A=UtmEcAh4cPgC3w_vdTPg6kkjgHVQXHTYRmA@mail.gmail.com>
2024-02-19 23:43       ` eugenio gigante
2024-02-20  0:32   ` Junio C Hamano

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFJh0PTiN18LcKP6LW0d1u2gkodBD2cOJRBzU_subBaFpzM=CA@mail.gmail.com' \
    --to=giganteeugenio2@gmail.com \
    --cc=git@vger.kernel.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).