On Thu, Mar 8, 2012 at 2:18 PM, Junio C Hamano <gitster@xxxxxxxxx> wrote: > René Scharfe <rene.scharfe@xxxxxxxxxxxxxx> writes: > >> Am 07.03.2012 22:59, schrieb Junio C Hamano: >>> René Scharfe<rene.scharfe@xxxxxxxxxxxxxx> writes: >>> >>>> Am 05.03.2012 22:34, schrieb Junio C Hamano: >>>> >>>>> +#define util_as_int(elem) ((intptr_t)((elem)->util)) >>>> >>>> Something that actually returns an int would fit the name better. ;) >>> >>> The particular type would not matter to the callers of the helper >>> macro, would it? >> >> Three of the five callers introduced in that commit cast the result to >> int and the remaining two don't care, so it actually does seem to >> matter for most of them, strictly speaking. When I see a nit, I can't >> resist the urge to pick it, apparently. > > Unfortunately, replacing intptr_t with int or casting the above > again as int will result in > > builtin/fmt-merge-msg.c: In function 'record_person': > builtin/fmt-merge-msg.c:213: error: cast to pointer from integer of different size > > So... Out of the frying pan, into the fire... builtin/fmt-merge-msg.c: In function ‘record_person’: builtin/fmt-merge-msg.c:213:34: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] builtin/fmt-merge-msg.c: In function ‘cmp_string_list_util_as_int’: builtin/fmt-merge-msg.c:219:9: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] builtin/fmt-merge-msg.c:219:26: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] builtin/fmt-merge-msg.c: In function ‘add_people_count’: builtin/fmt-merge-msg.c:229:8: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] builtin/fmt-merge-msg.c:231:8: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] builtin/fmt-merge-msg.c:235:8: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] I see slightly different code in pu than in next, but it produces the same warnings on my 64-bit Linux machine. Here's a fix against next: -- >8 -- Subject: [PATCH] Appease compiler pedantry with an extra cast Recently git repurposed a pointer as an integer to hold some counter which git fancies. Casting directly from 'pointer' to 'int' ((int)(void*)&x) causes a possible size mismatch because pointers can be bigger than ints. In such a situation, the compiler complains: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] Cast the value through intptr_t first to quell compiler complaints about how this gun appears to be aimed near our feet. Then cast this value to an int; this path assures the compiler we are smarter than we look, or at least that we intend to aim the gun this way for a reason. --- builtin/fmt-merge-msg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index 8ddefb3..fee65e0 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -182,7 +182,7 @@ static void add_branch_desc(struct strbuf *out, const char *name) strbuf_release(&desc); } -#define util_as_int(elem) ((int)((elem)->util)) +#define util_as_int(elem) ((int)(intptr_t)((elem)->util)) static void record_person(int which, struct string_list *people, struct commit *commit) -- 1.7.9.3 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html