ident.c: Use const qualifier when possible
PATCH 1/2 ident.c: Use const qualifier when possible
--- ident.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
ident.c +3 -3
@@ -9,7 +9,7 @@static char git_default_date[50 ]; -static void copy_gecos (struct passwd *w,char *name,int sz) +static void copy_gecos (const struct passwd *w,char *name,int sz) {char *src, *dst;int len, nlen;
@@ -43,7 +43,7 @@ static void copy_gecos(struct passwd *w, char *name, int sz) } -static void copy_email (struct passwd *pw) +static void copy_email (const struct passwd *pw) {/* * Make up a fake email address
@@ -172,7 +172,7 @@ static int copy(char *buf, int size, int offset, const char *src)static const char au_env[] ="GIT_AUTHOR_NAME" ;static const char co_env[] ="GIT_COMMITTER_NAME" ; -static const char *env_hint = +static const char const *env_hint ="\n" "*** Your name cannot be determined from your system services (gecos).\n" "\n"
Signature · 1 line
1.5.1.1.86.gfd56-dirty
ident.c static int copy(char *buf, int size, int offset, const char *src) · line 175
Quoted 2 lines · Luiz Fernando N. Capitulino
ident.c +1
-1-static const char *env_hint = +static const char const *env_hint =
char c; // c is a char char *p; // p is a pointer, *p is a char const char c; // c is a const char [1] char const c; // c is a const char [1] const char *p; // p is a pointer, *p is a const char [2] char const *p; // p is a pointer, *p is a const char [2] char *const p; // p is a const-pointer, *p is a char
const char *const p; // p is a const-pointer, *p is a const-char
[1] Semantically identical
[2] Semantically identical
You can see then that
const char const *env_hint
is redundant, it's simply saying twice that (*env_hint) is const.
Andy
Signature · 2 lines
Dr Andy Parkins, M Eng (hons), MIET [email protected]
Quoted 10 lines · Andy Parkins
ident.c static int copy(char *buf, int size, int offset, const char *src) · line 175
Quoted 2 lines · Luiz Fernando N. Capitulino
ident.c +1
-1-static const char *env_hint = +static const char const *env_hint =You can see then that
const char const
*env_hintis redundant, it's simply saying twice that (
*env_hint) is const.
I think he wanted to say
static const char *const env_hint = ...
Em Sun, 15 Apr 2007 13:14:57 -0700
Junio C Hamano <[email protected]> escreveu:
| Andy Parkins <[email protected]> writes: | | > On Sunday 2007, April 15, Luiz Fernando N. Capitulino wrote: | > | >> -static const char *env_hint = | >> +static const char const *env_hint = | > | > You can see then that | > | > const char const *env_hint | > | > is redundant, it's simply saying twice that (*env_hint) is const. | | I think he wanted to say | | static const char *const env_hint = ...
Urgh, yes. And it's not possible to make the pointer const
because we change the value it points to (-2 for me).
Updated version follows. I don't need to send the second
again, right?
From: Luiz Fernando N. Capitulino <[email protected]>
Subject: [PATCH] ident.c: Use const qualifier for 'struct passwd' parameters
--- ident.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
ident.c +2 -2
@@ -9,7 +9,7 @@static char git_default_date[50 ]; -static void copy_gecos (struct passwd *w,char *name,int sz) +static void copy_gecos (const struct passwd *w,char *name,int sz) {char *src, *dst;int len, nlen;
@@ -43,7 +43,7 @@ static void copy_gecos(struct passwd *w, char *name, int sz) } -static void copy_email (struct passwd *pw) +static void copy_email (const struct passwd *pw) {/* * Make up a fake email address
Signature · 1 line
1.5.1.1.86.gfd56-dirty