git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [GSoC] Use unsigned integral type for collection of bits
@ 2024-02-18 11:36 eugenio gigante
  2024-02-18 19:09 ` Eric Sunshine
  0 siblings, 1 reply; 4+ messages in thread
From: eugenio gigante @ 2024-02-18 11:36 UTC (permalink / raw)
  To: git

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/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-02-20  0:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-18 11:36 [GSoC] Use unsigned integral type for collection of bits eugenio gigante
2024-02-18 19:09 ` 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

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).