threads / patch / 43548

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

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

## tl;dr

2 messages between Nov 5, 2006 and Nov 5, 2006. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Shawn O. Pearce· Nov 5, 2006, 05:35 UTC · lore

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

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.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 builtin-apply.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to builtin-apply.c +1 −1
diff --git a/builtin-apply.c b/builtin-apply.c
index db7cdce..d7b3cea 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -43,7 +43,7 @@ static int apply_verbosely;
 static int no_add;
 static int show_index_info;
 static int line_termination = '\n';
-static unsigned long p_context = -1;
+static unsigned long p_context = (unsigned long)-1;
 static const char apply_usage[] =
 "git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--cached] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [--reverse] [--reject] [--verbose] [-z] [-pNUM] [-CNUM] [--whitespace=<nowarn|warn|error|error-all|strip>] <patch>...";
 
-- 
1.4.3.3.g9621
Junio C Hamano· Nov 5, 2006, 07:06 UTC · re: Shawn O. Pearce · lore
"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.

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.

In other words, how about this patch instead?
-- >8 --
Show changes to builtin-apply.c +1 −1
diff --git a/builtin-apply.c b/builtin-apply.c
index db7cdce..aad5526 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -43,7 +43,7 @@ static int apply_verbosely;
 static int no_add;
 static int show_index_info;
 static int line_termination = '\n';
-static unsigned long p_context = -1;
+static unsigned long p_context = ULONG_MAX;
 static const char apply_usage[] =
 "git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--cached] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [--reverse] [--reject] [--verbose] [-z] [-pNUM] [-CNUM] [--whitespace=<nowarn|warn|error|error-all|strip>] <patch>...";
 

← back to recent threads