From: Junio C Hamano <gitster@pobox.com>
To: "Philip Oakley" <philipoakley@iee.org>
Cc: "Git List" <git@vger.kernel.org>
Subject: Re: unary minus operator applied to unsigned type, result still unsigned?
Date: Wed, 04 May 2016 16:19:56 -0700 [thread overview]
Message-ID: <xmqqoa8lcswz.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <74B59A4DF45C45AF9CDCF6662DDAEF1E@PhilipOakley> (Philip Oakley's message of "Wed, 4 May 2016 23:59:23 +0100")
"Philip Oakley" <philipoakley@iee.org> writes:
> I'm working on building Git on Visual Studio as part of the Git for Windows
> capability.
>
> The MSVC compiler is reporting:
>
> 1>..\sha1-lookup.c(100) : warning C4146: unary minus operator applied to
> unsigned type, result still unsigned
> 1>..\sha1-lookup.c(316) : warning C4146: unary minus operator applied to
> unsigned type, result still unsigned
>
> the two lines of code are the same, and the message suggests a bad
> return value:
>
> #100: return -lo-1;
>
> #316: return -lo-1;
>
>
> Should these be protected by an appropriate brackets/calculation
> (-1-lo) ? Or does
> gcc use an alternate assumption about unary minus conversion for functions
> returning int?
I think -lo-1 (which is carried out as unsigned) is further casted
back to signed int as part of the return from the function whose
type is signed int. This may be portable in practice, but changing
type of lo to signed int may be prudent.
sha1_pos() uses size_t, but returns "int", which is inconsistent
(size_t could be much larger). Either using int for hi/lo/mi, or
using ssize_t and returning ssize_t would make sense.
next prev parent reply other threads:[~2016-05-04 23:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-04 22:59 unary minus operator applied to unsigned type, result still unsigned? Philip Oakley
2016-05-04 23:19 ` Junio C Hamano [this message]
2016-05-05 21:39 ` Philip Oakley
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=xmqqoa8lcswz.fsf@gitster.mtv.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=philipoakley@iee.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox