Re: [PATCH 1/3] Apply obvious numerical cast for stupid C compilers.

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

 



Junio C Hamano <junkio@xxxxxxx> wrote:
> "Shawn O. Pearce" <spearce@xxxxxxxxxxx> writes:
> 
> > At least one (older) version of the Solaris C compiler won't allow
> > 'unsigned long x = -1' without explicitly casting -1 to a type of
> > unsigned long.  As annoying as it may be to explicitly perform the
> > cast the compiler is right; -1 is not an unsigned value.
> 
> Is the compiler really _right_?  The usual integral promotion
> rules should apply if it claims to be a C compiler, I would
> think.

I'm rusty on my C; but I would expect an error if I tried to assign
a clearly negative value into an unsigned value, especially in a
case like this.  It could be compiler is wrong, but as a programmer
I'd want to know I wrote something stupid like that, because maybe
the variable should have been signed.  :-)
 
> But I think the code actually wants ULONG_MAX there.  Is that
> symbolic constant available at the point of offending
> initialization with the header files we already include, I
> wonder.

Yes, I agree.  I almost changed it to ULONG_MAX but didn't since
the original author felt -1 was the better choice here.  *shrug*

For what its worth ULONG_MAX works on my Mac OS X system.

Tomorrow when I have access to that "broken" platform again I'll
try ULONG_MAX and see if it compiles there.

-- 
Shawn.
-
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]