path: root/builtin/describe.c
diff options
authorEric Wong <>2019-10-06 23:30:41 (GMT)
committerJunio C Hamano <>2019-10-07 01:20:11 (GMT)
commit23dee69f53cf5024ca79e0b707dcb03c63f33bef (patch)
treee99f2fd2a4e1fe622451eeaafa8c37b40413ec10 /builtin/describe.c
parentc8e424c9c94d97b18cd335be17f32a8ce94a5b7f (diff)
OFFSETOF_VAR macro to simplify hashmap iterators
While we cannot rely on a `__typeof__' operator being portable to use with `offsetof'; we can calculate the pointer offset using an existing pointer and the address of a member using pointer arithmetic for compilers without `__typeof__'. This allows us to simplify usage of hashmap iterator macros by not having to specify a type when a pointer of that type is already given. In the future, list iterator macros (e.g. list_for_each_entry) may also be implemented using OFFSETOF_VAR to save hackers the trouble of using container_of/list_entry macros and without relying on non-portable `__typeof__'. v3: use `__typeof__' to avoid clang warnings Signed-off-by: Eric Wong <> Reviewed-by: Derrick Stolee <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/describe.c')
1 files changed, 1 insertions, 1 deletions
diff --git a/builtin/describe.c b/builtin/describe.c
index 8cf2cd9..1caf98f 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -333,7 +333,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
struct commit_name *n;
- hashmap_for_each_entry(&names, &iter, n, struct commit_name,
+ hashmap_for_each_entry(&names, &iter, n,
entry /* member name */) {
c = lookup_commit_reference_gently(the_repository,
&n->peeled, 1);