Re: unary minus operator applied to unsigned type, result still unsigned?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Philip Oakley" <philipoakley@xxxxxxx> 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.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]