Mercurial > vim
diff src/macros.h @ 9570:695186e11daa v7.4.2062
commit https://github.com/vim/vim/commit/840268400dc8fda62a14f8a084e8b1ea46619454
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jul 17 20:37:43 2016 +0200
patch 7.4.2062
Problem: Using dummy variable to compute struct member offset.
Solution: Use offsetof().
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 17 Jul 2016 20:45:05 +0200 |
parents | caed4b2d305f |
children | bff8a09016a5 |
line wrap: on
line diff
--- a/src/macros.h +++ b/src/macros.h @@ -353,3 +353,14 @@ # endif # endif #endif + +/* + * In a hashtab item "hi_key" points to "di_key" in a dictitem. + * This avoids adding a pointer to the hashtab item. + * DI2HIKEY() converts a dictitem pointer to a hashitem key pointer. + * HIKEY2DI() converts a hashitem key pointer to a dictitem pointer. + * HI2DI() converts a hashitem pointer to a dictitem pointer. + */ +# define DI2HIKEY(di) ((di)->di_key) +# define HIKEY2DI(p) ((dictitem_T *)(p - offsetof(dictitem_T, di_key))) +# define HI2DI(hi) HIKEY2DI((hi)->hi_key)