git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 6/6] sparse: Fix mingw_main() argument number/type errors
@ 2013-04-27 19:19 Ramsay Jones
  2013-04-28  0:31 ` René Scharfe
  0 siblings, 1 reply; 6+ messages in thread
From: Ramsay Jones @ 2013-04-27 19:19 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: GIT Mailing-list


Sparse issues 68 errors (two errors for each main() function) such
as the following:

      SP git.c
  git.c:510:5: error: too many arguments for function mingw_main
  git.c:510:5: error: symbol 'mingw_main' redeclared with different type \
    (originally declared at git.c:510) - different argument counts

The errors are caused by the 'main' macro used by the MinGW build
to provide a replacement main() function. The original main function
is effectively renamed to 'mingw_main' and is called from the new
main function. The replacement main is used to execute certain actions
common to all git programs on MinGW (e.g. ensure the standard I/O
streams are in binary mode).

In order to suppress the errors, we change the macro to include the
parameters in the declaration of the mingw_main function.

Unfortunately, this change provokes both sparse and gcc to complain
about 9 calls to mingw_main(), such as the following:

      CC git.o
  git.c: In function 'main':
  git.c:510: warning: passing argument 2 of 'mingw_main' from \
    incompatible pointer type
  git.c:510: note: expected 'const char **' but argument is of \
    type 'char **'

In order to suppress these warnings, since both of the main
functions need to be declared with the same prototype, we
change the declaration of the 9 main functions, thus:

    int main(int argc, char **argv)

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---
 compat/mingw.h       | 4 ++--
 credential-store.c   | 4 ++--
 fast-import.c        | 4 ++--
 git.c                | 3 ++-
 remote-testsvn.c     | 2 +-
 test-chmtime.c       | 2 +-
 test-index-version.c | 2 +-
 test-mergesort.c     | 2 +-
 test-parse-options.c | 4 ++--
 test-subprocess.c    | 4 ++--
 10 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/compat/mingw.h b/compat/mingw.h
index 3036980..bd0a88b 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -346,8 +346,8 @@ extern CRITICAL_SECTION pinfo_cs;
  */
 
 #define main(c,v) dummy_decl_mingw_main(); \
-static int mingw_main(); \
-int main(int argc, const char **argv) \
+static int mingw_main(c,v); \
+int main(int argc, char **argv) \
 { \
 	extern CRITICAL_SECTION pinfo_cs; \
 	_fmode = _O_BINARY; \
diff --git a/credential-store.c b/credential-store.c
index 26f7589..f9146e5 100644
--- a/credential-store.c
+++ b/credential-store.c
@@ -114,7 +114,7 @@ static int lookup_credential(const char *fn, struct credential *c)
 	return c->username && c->password;
 }
 
-int main(int argc, const char **argv)
+int main(int argc, char **argv)
 {
 	const char * const usage[] = {
 		"git credential-store [options] <action>",
@@ -131,7 +131,7 @@ int main(int argc, const char **argv)
 
 	umask(077);
 
-	argc = parse_options(argc, argv, NULL, options, usage, 0);
+	argc = parse_options(argc, (const char **)argv, NULL, options, usage, 0);
 	if (argc != 1)
 		usage_with_options(usage, options);
 	op = argv[0];
diff --git a/fast-import.c b/fast-import.c
index 5f539d7..6d94453 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -297,7 +297,7 @@ static int failure;
 static FILE *pack_edges;
 static unsigned int show_stats = 1;
 static int global_argc;
-static const char **global_argv;
+static char **global_argv;
 
 /* Memory pools */
 static size_t mem_pool_alloc = 2*1024*1024 - sizeof(struct mem_pool);
@@ -3347,7 +3347,7 @@ static void parse_argv(void)
 		read_marks();
 }
 
-int main(int argc, const char **argv)
+int main(int argc, char **argv)
 {
 	unsigned int i;
 
diff --git a/git.c b/git.c
index 1ada169..7dd07aa 100644
--- a/git.c
+++ b/git.c
@@ -507,8 +507,9 @@ static int run_argv(int *argcp, const char ***argv)
 }
 
 
-int main(int argc, const char **argv)
+int main(int argc, char **av)
 {
+	const char **argv = (const char **) av;
 	const char *cmd;
 
 	startup_info = &git_startup_info;
diff --git a/remote-testsvn.c b/remote-testsvn.c
index 5ddf11c..d7cd5d2 100644
--- a/remote-testsvn.c
+++ b/remote-testsvn.c
@@ -286,7 +286,7 @@ static int do_command(struct strbuf *line)
 	return 0;
 }
 
-int main(int argc, const char **argv)
+int main(int argc, char **argv)
 {
 	struct strbuf buf = STRBUF_INIT, url_sb = STRBUF_INIT,
 			private_ref_sb = STRBUF_INIT, marksfilename_sb = STRBUF_INIT,
diff --git a/test-chmtime.c b/test-chmtime.c
index 02b42ba..94903c4 100644
--- a/test-chmtime.c
+++ b/test-chmtime.c
@@ -56,7 +56,7 @@ static int timespec_arg(const char *arg, long int *set_time, int *set_eq)
 	return 1;
 }
 
-int main(int argc, const char *argv[])
+int main(int argc, char *argv[])
 {
 	static int verbose;
 
diff --git a/test-index-version.c b/test-index-version.c
index bfaad9e..05d4699 100644
--- a/test-index-version.c
+++ b/test-index-version.c
@@ -1,6 +1,6 @@
 #include "cache.h"
 
-int main(int argc, const char **argv)
+int main(int argc, char **argv)
 {
 	struct cache_header hdr;
 	int version;
diff --git a/test-mergesort.c b/test-mergesort.c
index 3f388b4..ea3b959 100644
--- a/test-mergesort.c
+++ b/test-mergesort.c
@@ -22,7 +22,7 @@ static int compare_strings(const void *a, const void *b)
 	return strcmp(x->text, y->text);
 }
 
-int main(int argc, const char **argv)
+int main(int argc, char **argv)
 {
 	struct line *line, *p = NULL, *lines = NULL;
 	struct strbuf sb = STRBUF_INIT;
diff --git a/test-parse-options.c b/test-parse-options.c
index 3c9510a..434e8b8 100644
--- a/test-parse-options.c
+++ b/test-parse-options.c
@@ -29,7 +29,7 @@ static int number_callback(const struct option *opt, const char *arg, int unset)
 	return 0;
 }
 
-int main(int argc, const char **argv)
+int main(int argc, char **argv)
 {
 	const char *prefix = "prefix/";
 	const char *usage[] = {
@@ -81,7 +81,7 @@ int main(int argc, const char **argv)
 	};
 	int i;
 
-	argc = parse_options(argc, argv, prefix, options, usage, 0);
+	argc = parse_options(argc, (const char **)argv, prefix, options, usage, 0);
 
 	printf("boolean: %d\n", boolean);
 	printf("integer: %u\n", integer);
diff --git a/test-subprocess.c b/test-subprocess.c
index f2d4c0d..93525eb 100644
--- a/test-subprocess.c
+++ b/test-subprocess.c
@@ -1,7 +1,7 @@
 #include "cache.h"
 #include "run-command.h"
 
-int main(int argc, const char **argv)
+int main(int argc, char **argv)
 {
 	struct child_process cp;
 	int nogit = 0;
@@ -15,6 +15,6 @@ int main(int argc, const char **argv)
 	}
 	memset(&cp, 0, sizeof(cp));
 	cp.git_cmd = 1;
-	cp.argv = argv + 1;
+	cp.argv = (const char **)argv + 1;
 	return run_command(&cp);
 }
-- 
1.8.2

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 6/6] sparse: Fix mingw_main() argument number/type errors
  2013-04-27 19:19 [PATCH 6/6] sparse: Fix mingw_main() argument number/type errors Ramsay Jones
@ 2013-04-28  0:31 ` René Scharfe
  2013-04-28 19:31   ` Junio C Hamano
  2013-04-29 21:52   ` Ramsay Jones
  0 siblings, 2 replies; 6+ messages in thread
From: René Scharfe @ 2013-04-28  0:31 UTC (permalink / raw)
  To: Ramsay Jones; +Cc: Junio C Hamano, GIT Mailing-list

Am 27.04.2013 21:19, schrieb Ramsay Jones:
> In order to suppress these warnings, since both of the main
> functions need to be declared with the same prototype, we
> change the declaration of the 9 main functions, thus:
> 
>      int main(int argc, char **argv)

Why not take the opposite direction with a patch like this?  It's quick
and dirty and based on v1.8.1.msysgit.1, as that was the version I had
lying around here, but you get the idea.

René

---
 compat/mingw.h          |  4 ++--
 daemon.c                | 16 ++++++++--------
 http-backend.c          |  2 +-
 imap-send.c             |  2 +-
 sh-i18n--envsubst.c     |  2 +-
 shell.c                 |  2 +-
 show-index.c            |  2 +-
 test-ctype.c            |  2 +-
 test-date.c             |  8 ++++----
 test-delta.c            |  2 +-
 test-dump-cache-tree.c  |  2 +-
 test-genrandom.c        |  2 +-
 test-line-buffer.c      |  2 +-
 test-match-trees.c      |  2 +-
 test-mktemp.c           |  2 +-
 test-path-utils.c       |  4 ++--
 test-regex.c            |  2 +-
 test-revision-walking.c |  2 +-
 test-run-command.c      |  2 +-
 test-scrap-cache-tree.c |  2 +-
 test-sha1.c             |  2 +-
 test-sigchain.c         |  2 +-
 test-string-list.c      |  2 +-
 test-svn-fe.c           |  4 ++--
 upload-pack.c           |  6 +++---
 25 files changed, 40 insertions(+), 40 deletions(-)

diff --git a/compat/mingw.h b/compat/mingw.h
index 389ae01..74e7b87 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -452,11 +452,11 @@ int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen);
 
 void mingw_startup();
 #define main(c,v) dummy_decl_mingw_main(); \
-static int mingw_main(); \
+static int mingw_main(int, const char **); \
 int main(int argc, const char **argv) \
 { \
 	mingw_startup(); \
-	return mingw_main(__argc, __argv); \
+	return mingw_main(argc, argv); \
 } \
 static int mingw_main(c,v)
 
diff --git a/daemon.c b/daemon.c
index 4602b46..f4186a7 100644
--- a/daemon.c
+++ b/daemon.c
@@ -36,15 +36,15 @@ static const char daemon_usage[] =
 "           [<directory>...]";
 
 /* List of acceptable pathname prefixes */
-static char **ok_paths;
+static const char **ok_paths;
 static int strict_paths;
 
 /* If this is set, git-daemon-export-ok is not required */
 static int export_all_trees;
 
 /* Take all paths relative to this one if non-NULL */
-static char *base_path;
-static char *interpolated_path;
+static const char *base_path;
+static const char *interpolated_path;
 static int base_path_relaxed;
 
 /* Flag indicating client sent extra args. */
@@ -196,7 +196,7 @@ static const char *path_ok(char *directory)
 	}
 
 	if ( ok_paths && *ok_paths ) {
-		char **pp;
+		const char **pp;
 		int pathlen = strlen(path);
 
 		/* The validation is done on the paths after enter_repo
@@ -257,7 +257,7 @@ static int daemon_error(const char *dir, const char *msg)
 	return -1;
 }
 
-static char *access_hook;
+static const char *access_hook;
 
 static int run_access_hook(struct daemon_service *service, const char *dir, const char *path)
 {
@@ -739,7 +739,7 @@ static void check_dead_children(void)
 			cradle = &blanket->next;
 }
 
-static char **cld_argv;
+static const char **cld_argv;
 static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
 {
 	struct child_process cld = { NULL };
@@ -1164,7 +1164,7 @@ static int serve(struct string_list *listen_addr, int listen_port,
 	return service_loop(&socklist);
 }
 
-int main(int argc, char **argv)
+int main(int argc, const char **argv)
 {
 	int listen_port = 0;
 	struct string_list listen_addr = STRING_LIST_INIT_NODUP;
@@ -1179,7 +1179,7 @@ int main(int argc, char **argv)
 	git_extract_argv0_path(argv[0]);
 
 	for (i = 1; i < argc; i++) {
-		char *arg = argv[i];
+		const char *arg = argv[i];
 
 		if (!prefixcmp(arg, "--listen=")) {
 			string_list_append(&listen_addr, xstrdup_tolower(arg + 9));
diff --git a/http-backend.c b/http-backend.c
index f50e77f..ce164bb 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -533,7 +533,7 @@ static struct service_cmd {
 	{"POST", "/git-receive-pack$", service_rpc}
 };
 
-int main(int argc, char **argv)
+int main(int argc, const char **argv)
 {
 	char *method = getenv("REQUEST_METHOD");
 	char *dir;
diff --git a/imap-send.c b/imap-send.c
index d42e471..ec98934 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -1502,7 +1502,7 @@ static int git_imap_config(const char *key, const char *val, void *cb)
 	return 0;
 }
 
-int main(int argc, char **argv)
+int main(int argc, const char **argv)
 {
 	struct msg_data all_msgs, msg;
 	struct store *ctx = NULL;
diff --git a/sh-i18n--envsubst.c b/sh-i18n--envsubst.c
index 5ddd688..c3d0654 100644
--- a/sh-i18n--envsubst.c
+++ b/sh-i18n--envsubst.c
@@ -64,7 +64,7 @@ static void note_variables (const char *string);
 static void subst_from_stdin (void);
 
 int
-main (int argc, char *argv[])
+main (int argc, const char *argv[])
 {
   /* Default values for command line options.  */
   /* unsigned short int show_variables = 0; */
diff --git a/shell.c b/shell.c
index 06a394c..9ec4491 100644
--- a/shell.c
+++ b/shell.c
@@ -129,7 +129,7 @@ static struct commands {
 	{ NULL },
 };
 
-int main(int argc, char **argv)
+int main(int argc, const char **argv)
 {
 	char *prog;
 	const char **user_argv;
diff --git a/show-index.c b/show-index.c
index 5a9eed7..651a115 100644
--- a/show-index.c
+++ b/show-index.c
@@ -4,7 +4,7 @@
 static const char show_index_usage[] =
 "git show-index < <packed archive index>";
 
-int main(int argc, char **argv)
+int main(int argc, const char **argv)
 {
 	int i;
 	unsigned nr;
diff --git a/test-ctype.c b/test-ctype.c
index 707a821..694dcfb 100644
--- a/test-ctype.c
+++ b/test-ctype.c
@@ -28,7 +28,7 @@ static int is_in(const char *s, int ch)
 #define LOWER "abcdefghijklmnopqrstuvwxyz"
 #define UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 
-int main(int argc, char **argv)
+int main(int argc, const char **argv)
 {
 	TEST_CLASS(isdigit, DIGIT);
 	TEST_CLASS(isspace, " \n\r\t");
diff --git a/test-date.c b/test-date.c
index 10afaab..00c9e93 100644
--- a/test-date.c
+++ b/test-date.c
@@ -5,7 +5,7 @@ static const char *usage_msg = "\n"
 "  test-date parse [date]...\n"
 "  test-date approxidate [date]...\n";
 
-static void show_dates(char **argv, struct timeval *now)
+static void show_dates(const char **argv, struct timeval *now)
 {
 	struct strbuf buf = STRBUF_INIT;
 
@@ -17,7 +17,7 @@ static void show_dates(char **argv, struct timeval *now)
 	strbuf_release(&buf);
 }
 
-static void parse_dates(char **argv, struct timeval *now)
+static void parse_dates(const char **argv, struct timeval *now)
 {
 	for (; *argv; argv++) {
 		char result[100];
@@ -34,7 +34,7 @@ static void parse_dates(char **argv, struct timeval *now)
 	}
 }
 
-static void parse_approxidate(char **argv, struct timeval *now)
+static void parse_approxidate(const char **argv, struct timeval *now)
 {
 	for (; *argv; argv++) {
 		time_t t;
@@ -43,7 +43,7 @@ static void parse_approxidate(char **argv, struct timeval *now)
 	}
 }
 
-int main(int argc, char **argv)
+int main(int argc, const char **argv)
 {
 	struct timeval now;
 	const char *x;
diff --git a/test-delta.c b/test-delta.c
index af40a3c..b697e87 100644
--- a/test-delta.c
+++ b/test-delta.c
@@ -15,7 +15,7 @@
 static const char usage_str[] =
 	"test-delta (-d|-p) <from_file> <data_file> <out_file>";
 
-int main(int argc, char *argv[])
+int main(int argc, const char *argv[])
 {
 	int fd;
 	struct stat st;
diff --git a/test-dump-cache-tree.c b/test-dump-cache-tree.c
index a6ffdf3..ab75fe0 100644
--- a/test-dump-cache-tree.c
+++ b/test-dump-cache-tree.c
@@ -54,7 +54,7 @@ static int dump_cache_tree(struct cache_tree *it,
 	return errs;
 }
 
-int main(int ac, char **av)
+int main(int ac, const char **av)
 {
 	struct cache_tree *another = cache_tree();
 	if (read_cache() < 0)
diff --git a/test-genrandom.c b/test-genrandom.c
index b3c28d9..fa63cfd 100644
--- a/test-genrandom.c
+++ b/test-genrandom.c
@@ -6,7 +6,7 @@
 
 #include "git-compat-util.h"
 
-int main(int argc, char *argv[])
+int main(int argc, const char *argv[])
 {
 	unsigned long count, next = 0;
 	unsigned char *c;
diff --git a/test-line-buffer.c b/test-line-buffer.c
index ef1d7ba..a018fd7 100644
--- a/test-line-buffer.c
+++ b/test-line-buffer.c
@@ -50,7 +50,7 @@ static void handle_line(const char *line, struct line_buffer *stdin_buf)
 	handle_command(line, arg + 1, stdin_buf);
 }
 
-int main(int argc, char *argv[])
+int main(int argc, const char *argv[])
 {
 	struct line_buffer stdin_buf = LINE_BUFFER_INIT;
 	struct line_buffer file_buf = LINE_BUFFER_INIT;
diff --git a/test-match-trees.c b/test-match-trees.c
index a3c4688..2af5d80 100644
--- a/test-match-trees.c
+++ b/test-match-trees.c
@@ -1,7 +1,7 @@
 #include "cache.h"
 #include "tree.h"
 
-int main(int ac, char **av)
+int main(int ac, const char **av)
 {
 	unsigned char hash1[20], hash2[20], shifted[20];
 	struct tree *one, *two;
diff --git a/test-mktemp.c b/test-mktemp.c
index c8c5421..6f3542c 100644
--- a/test-mktemp.c
+++ b/test-mktemp.c
@@ -3,7 +3,7 @@
  */
 #include "git-compat-util.h"
 
-int main(int argc, char *argv[])
+int main(int argc, const char *argv[])
 {
 	if (argc != 2)
 		usage("Expected 1 parameter defining the temporary file template");
diff --git a/test-path-utils.c b/test-path-utils.c
index 0092cbf..e02154c 100644
--- a/test-path-utils.c
+++ b/test-path-utils.c
@@ -28,7 +28,7 @@ static int normalize_ceiling_entry(struct string_list_item *item, void *unused)
 	return 1;
 }
 
-int main(int argc, char **argv)
+int main(int argc, const char **argv)
 {
 	if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) {
 		char *buf = xmalloc(PATH_MAX + 1);
@@ -85,7 +85,7 @@ int main(int argc, char **argv)
 	}
 
 	if (argc >= 4 && !strcmp(argv[1], "prefix_path")) {
-		char *prefix = argv[2];
+		const char *prefix = argv[2];
 		int prefix_len = strlen(prefix);
 		int nongit_ok;
 		setup_git_directory_gently(&nongit_ok);
diff --git a/test-regex.c b/test-regex.c
index b5bfd54..22536aa 100644
--- a/test-regex.c
+++ b/test-regex.c
@@ -1,6 +1,6 @@
 #include <git-compat-util.h>
 
-int main(int argc, char **argv)
+int main(int argc, const char **argv)
 {
 	char *pat = "[^={} \t]+";
 	char *str = "={}\nfred";
diff --git a/test-revision-walking.c b/test-revision-walking.c
index 3ade02c..d305962 100644
--- a/test-revision-walking.c
+++ b/test-revision-walking.c
@@ -45,7 +45,7 @@ static int run_revision_walk(void)
 	return got_revision;
 }
 
-int main(int argc, char **argv)
+int main(int argc, const char **argv)
 {
 	if (argc < 2)
 		return 1;
diff --git a/test-run-command.c b/test-run-command.c
index 37918e1..00f040b 100644
--- a/test-run-command.c
+++ b/test-run-command.c
@@ -13,7 +13,7 @@
 #include <string.h>
 #include <errno.h>
 
-int main(int argc, char **argv)
+int main(int argc, const char **argv)
 {
 	struct child_process proc;
 
diff --git a/test-scrap-cache-tree.c b/test-scrap-cache-tree.c
index 4728013..cae5bcb 100644
--- a/test-scrap-cache-tree.c
+++ b/test-scrap-cache-tree.c
@@ -4,7 +4,7 @@
 
 static struct lock_file index_lock;
 
-int main(int ac, char **av)
+int main(int ac, const char **av)
 {
 	int fd = hold_locked_index(&index_lock, 1);
 	if (read_cache() < 0)
diff --git a/test-sha1.c b/test-sha1.c
index 80daba9..aed67af 100644
--- a/test-sha1.c
+++ b/test-sha1.c
@@ -1,6 +1,6 @@
 #include "cache.h"
 
-int main(int ac, char **av)
+int main(int ac, const char **av)
 {
 	git_SHA_CTX ctx;
 	unsigned char sha1[20];
diff --git a/test-sigchain.c b/test-sigchain.c
index 42db234..b00e17f 100644
--- a/test-sigchain.c
+++ b/test-sigchain.c
@@ -13,7 +13,7 @@ X(two)
 X(three)
 #undef X
 
-int main(int argc, char **argv) {
+int main(int argc, const char **argv) {
 	sigchain_push(SIGTERM, one);
 	sigchain_push(SIGTERM, two);
 	sigchain_push(SIGTERM, three);
diff --git a/test-string-list.c b/test-string-list.c
index 00ce6c9..f59cf05 100644
--- a/test-string-list.c
+++ b/test-string-list.c
@@ -41,7 +41,7 @@ static int prefix_cb(struct string_list_item *item, void *cb_data)
 	return !prefixcmp(item->string, prefix);
 }
 
-int main(int argc, char **argv)
+int main(int argc, const char **argv)
 {
 	if (argc == 5 && !strcmp(argv[1], "split")) {
 		struct string_list list = STRING_LIST_INIT_DUP;
diff --git a/test-svn-fe.c b/test-svn-fe.c
index 0f2d9a4..8ac4954 100644
--- a/test-svn-fe.c
+++ b/test-svn-fe.c
@@ -11,7 +11,7 @@
 static const char test_svnfe_usage[] =
 	"test-svn-fe (<dumpfile> | [-d] <preimage> <delta> <len>)";
 
-static int apply_delta(int argc, char *argv[])
+static int apply_delta(int argc, const char *argv[])
 {
 	struct line_buffer preimage = LINE_BUFFER_INIT;
 	struct line_buffer delta = LINE_BUFFER_INIT;
@@ -35,7 +35,7 @@ static int apply_delta(int argc, char *argv[])
 	return 0;
 }
 
-int main(int argc, char *argv[])
+int main(int argc, const char *argv[])
 {
 	if (argc == 2) {
 		if (svndump_init(argv[1]))
diff --git a/upload-pack.c b/upload-pack.c
index 6142421..71c72cc 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -780,9 +780,9 @@ static void upload_pack(void)
 	}
 }
 
-int main(int argc, char **argv)
+int main(int argc, const char **argv)
 {
-	char *dir;
+	const char *dir;
 	int i;
 	int strict = 0;
 
@@ -793,7 +793,7 @@ int main(int argc, char **argv)
 	read_replace_refs = 0;
 
 	for (i = 1; i < argc; i++) {
-		char *arg = argv[i];
+		const char *arg = argv[i];
 
 		if (arg[0] != '-')
 			break;

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 6/6] sparse: Fix mingw_main() argument number/type errors
  2013-04-28  0:31 ` René Scharfe
@ 2013-04-28 19:31   ` Junio C Hamano
  2013-04-29 16:10     ` René Scharfe
  2013-04-29 21:52   ` Ramsay Jones
  1 sibling, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2013-04-28 19:31 UTC (permalink / raw)
  To: René Scharfe; +Cc: Ramsay Jones, GIT Mailing-list

René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:

> Why not take the opposite direction with a patch like this?
> ...
> diff --git a/compat/mingw.h b/compat/mingw.h
> index 389ae01..74e7b87 100644
> --- a/compat/mingw.h
> +++ b/compat/mingw.h
> @@ -452,11 +452,11 @@ int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen);
>  
>  void mingw_startup();
>  #define main(c,v) dummy_decl_mingw_main(); \
> -static int mingw_main(); \
> +static int mingw_main(int, const char **); \
>  int main(int argc, const char **argv) \

But traditionally main is declared like 

	int main(int argc, char *argv[]);

without const, no?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 6/6] sparse: Fix mingw_main() argument number/type errors
  2013-04-28 19:31   ` Junio C Hamano
@ 2013-04-29 16:10     ` René Scharfe
  2013-04-29 23:30       ` Ramsay Jones
  0 siblings, 1 reply; 6+ messages in thread
From: René Scharfe @ 2013-04-29 16:10 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Ramsay Jones, GIT Mailing-list

Am 28.04.2013 21:31, schrieb Junio C Hamano:
> René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:
>
>> Why not take the opposite direction with a patch like this?
>> ...
>> diff --git a/compat/mingw.h b/compat/mingw.h
>> index 389ae01..74e7b87 100644
>> --- a/compat/mingw.h
>> +++ b/compat/mingw.h
>> @@ -452,11 +452,11 @@ int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen);
>>
>>   void mingw_startup();
>>   #define main(c,v) dummy_decl_mingw_main(); \
>> -static int mingw_main(); \
>> +static int mingw_main(int, const char **); \
>>   int main(int argc, const char **argv) \
>
> But traditionally main is declared like
>
> 	int main(int argc, char *argv[]);
>
> without const, no?

Yes, http://c-faq.com/ansi/maindecl.html and basically everybody else 
agree.  Now that I actually think about it, the only benefit of 
declaring argv constant I can find is that the const'ness could easily 
spread to other variables and function arguments where it may actually 
matter.  So please ignore my interjection.  Or perhaps it might be worth 
mentioning in the commit message that removal of that "const" improves 
the code's standard compliance.

René

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 6/6] sparse: Fix mingw_main() argument number/type errors
  2013-04-28  0:31 ` René Scharfe
  2013-04-28 19:31   ` Junio C Hamano
@ 2013-04-29 21:52   ` Ramsay Jones
  1 sibling, 0 replies; 6+ messages in thread
From: Ramsay Jones @ 2013-04-29 21:52 UTC (permalink / raw)
  To: René Scharfe; +Cc: Junio C Hamano, GIT Mailing-list

René Scharfe wrote:
> Am 27.04.2013 21:19, schrieb Ramsay Jones:
>> In order to suppress these warnings, since both of the main
>> functions need to be declared with the same prototype, we
>> change the declaration of the 9 main functions, thus:
>>
>>      int main(int argc, char **argv)
> 
> Why not take the opposite direction with a patch like this?  It's quick
> and dirty and based on v1.8.1.msysgit.1, as that was the version I had
> lying around here, but you get the idea.

The main reason (99%) was patch size. I only noticed a "recent trend"
to declare the main() with a 'const char **argv' parameter because,
over the years, I've had to keep adding to this patch. (Having said
that, I suspect it has only been about four additions in four years).

The other 1% is simply that it just looks wrong! (yeah, this new
'const' thingamajig has it's uses, but still ... :-D ).

Just FYI, the C99 standard has this to say:

    c99 standard 5.1.2.2.1 "Program startup"

    The function called at program startup is named main. The
    implementation declares no prototype for this function. It
    shall be defined with a return type of int and with no
    parameters:

        int main(void) { /* ... */ }

    or with two parameters (referred to here as argc and argv,
    though any names may be used, as they are local to the
    function in which they are declared);

        int main(int argc, char *argv[]) { /* ... */ }

    or equivalent;^9 or in some other implementation-defined
    manner.

    [note 9: Thus, int can be replaced by a typedef name
    defined as int, or the type of argv can be written as
    char **argv, and so on.]

    ...

        - The parameters argc and argv and the strings pointed
        to by the argv array shall be modifiable by the program,
        and retain their last-stored values between program
        startup and program termination.


That "... or in some other implementation-defined manner." tends
to make this text somewhat weak!

ATB,
Ramsay Jones

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 6/6] sparse: Fix mingw_main() argument number/type errors
  2013-04-29 16:10     ` René Scharfe
@ 2013-04-29 23:30       ` Ramsay Jones
  0 siblings, 0 replies; 6+ messages in thread
From: Ramsay Jones @ 2013-04-29 23:30 UTC (permalink / raw)
  To: René Scharfe; +Cc: Junio C Hamano, GIT Mailing-list

René Scharfe wrote:
> Am 28.04.2013 21:31, schrieb Junio C Hamano:
>> René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:
>>
>>> Why not take the opposite direction with a patch like this?
>>> ...
>>> diff --git a/compat/mingw.h b/compat/mingw.h
>>> index 389ae01..74e7b87 100644
>>> --- a/compat/mingw.h
>>> +++ b/compat/mingw.h
>>> @@ -452,11 +452,11 @@ int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen);
>>>
>>>   void mingw_startup();
>>>   #define main(c,v) dummy_decl_mingw_main(); \
>>> -static int mingw_main(); \
>>> +static int mingw_main(int, const char **); \
>>>   int main(int argc, const char **argv) \
>>
>> But traditionally main is declared like
>>
>> 	int main(int argc, char *argv[]);
>>
>> without const, no?
> 
> Yes, http://c-faq.com/ansi/maindecl.html and basically everybody else 
> agree.  Now that I actually think about it, the only benefit of 
> declaring argv constant I can find is that the const'ness could easily 
> spread to other variables and function arguments where it may actually 
> matter.  So please ignore my interjection.  Or perhaps it might be worth 
> mentioning in the commit message that removal of that "const" improves 
> the code's standard compliance.

Hmm, well, strictly speaking, I can't say that is true! (see previous
email). It is certainly true that it more closely follows the *spirit*
of the standard, if not the letter of the law.

ATB,
Ramsay Jones

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-04-29 23:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-27 19:19 [PATCH 6/6] sparse: Fix mingw_main() argument number/type errors Ramsay Jones
2013-04-28  0:31 ` René Scharfe
2013-04-28 19:31   ` Junio C Hamano
2013-04-29 16:10     ` René Scharfe
2013-04-29 23:30       ` Ramsay Jones
2013-04-29 21:52   ` Ramsay Jones

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).