Mercurial > dovecot > core-2.2
changeset 3194:d5935326e06f HEAD
Renamed ARRAY_ARG_SET_TYPE() to ARRAY_SET_TYPE() and updated comments.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 13 Mar 2005 00:38:06 +0200 |
parents | d0adece8a6a0 |
children | 10532f156263 |
files | src/lib/array.h |
diffstat | 1 files changed, 15 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/array.h Sat Mar 12 20:32:08 2005 +0200 +++ b/src/lib/array.h Sun Mar 13 00:38:06 2005 +0200 @@ -7,14 +7,14 @@ enabled, it also provides compile time type safety: If DEBUG is enabled, an extra variable is defined along with the array - itself. This is used to cast ARRAY_IDX() return value correctly, so + itself. This is used to cast array_idx() return value correctly, so compiler gives a warning if it's assigned into variable with a different type. Example usage: struct foo { - array_t ARRAY_DEFINE(bars, struct bar); + array_t ARRAY_DEFINE(bars, struct bar); ... }; @@ -23,6 +23,17 @@ struct bar *bar = array_idx(&foo->bars, 5); struct baz *baz = array_idx(&foo->bars, 5); // compiler warning + + When passing array_t as a parameter to function, or when it's otherwise + accessed in a way that the extra variable cannot be accessed, the code + won't compile. For situations like those, there's a ARRAY_SET_TYPE() macro. + + Example: + + void do_foo(array_t *bars) { + ARRAY_SET_TYPE(bars, struct foo); + struct foo *foo = array_idx(bars, 0); + } */ #if defined (DEBUG) && defined (__GNUC__) # define ARRAY_DEFINE(name, array_type) name; array_type *name ## __ ## type @@ -30,13 +41,13 @@ array_type *_array_tmp = *(array ## __ ## type); _array_tmp = NULL; \ array_create(array, pool, sizeof(array_type), init_count); \ } STMT_END -# define ARRAY_ARG_SET_TYPE(array, array_type) \ +# define ARRAY_SET_TYPE(array, array_type) \ array_type **array ## __ ## type = NULL #else # define ARRAY_DEFINE(name, array_type) name # define ARRAY_CREATE(array, pool, array_type, init_count) \ array_create(array, pool, sizeof(array_type), init_count); -# define ARRAY_ARG_SET_TYPE(array, array_type) +# define ARRAY_SET_TYPE(array, array_type) #endif struct array {