From: Shawn Pearce <spearce@spearce.org>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 1/3] Apply obvious numerical cast for stupid C compilers.
Date: Sun, 5 Nov 2006 02:18:05 -0500 [thread overview]
Message-ID: <20061105071805.GA4506@spearce.org> (raw)
In-Reply-To: <7v3b8ywewj.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <junkio@cox.net> wrote:
> "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 prev parent reply other threads:[~2006-11-05 7:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-05 5:35 [PATCH 1/3] Apply obvious numerical cast for stupid C compilers Shawn O. Pearce
2006-11-05 7:06 ` Junio C Hamano
2006-11-05 7:18 ` Shawn Pearce [this message]
2006-11-05 7:27 ` [PATCH 1/2] Use ULONG_MAX rather than implicit cast of -1 Shawn O. Pearce
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=20061105071805.GA4506@spearce.org \
--to=spearce@spearce.org \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/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;
as well as URLs for NNTP newsgroup(s).