git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Shawn Pearce <spearce@spearce.org>
Date
Nov 5, 2006, 07:18 UTC
Message-ID
<20061105071805.GA4506@spearce.org>
In-Reply-To
<7v3b8ywewj.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <junkio@cox.net> wrote:
Show 10 quoted lines
> "Shawn O. Pearce" <spearce@spearce.org> 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.

Next: Shawn O. Pearce
Message 1 of 2 in “Re: [PATCH 1/3] Apply obvious numerical cast for stupid C compilers.”
  1. Shawn PearceNov 5, 2006
  2. 1/2 Use ULONG_MAX rather than implicit cast of -1.Shawn O. Pearce, Nov 5, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.