Follow-up Comment #2, bug #13802 (project freeciv):

> It is really needed? Couldn't it be performed by adding
> a test in the iterating marco like: if (NULL != hash)?

If you mean in the specific iteration macros like
hash_keys_iterate, this would need to be repeated each
time a new macro like that is defined, and I wanted to
avoid the situation where the same code is duplicated
in the headers every time. One design goal of the
generic_iterate macro is to reduce the definition to
only the things that are different.

If you mean to put the NULL check in the generic_
iterate macro itself, it would have to be a check
on the iterator pointer, since the extra init
arguments are passed via macro varargs, and could
be completely absent or more than 1 (i.e. there is
no way to put them in an if-expression).

One reason I did not allow NULL iterator pointers is
so that I would not have to put NULL checks in all of
the iterator_*() functions and also in any code that
would use the init function outside of the generic_
iterate macro.

Iterator pointers are somewhat special in that the
memory is guaranteed to be on the stack; it is never
NULL. If we decide to use NULL iterator pointers in
one place, we would have to do away with this nice
property and assume that iterators could be NULL
almost everywhere.

We would not need the iterator.c file, but then we
would need a lot more NULL checks everywhere else, so
purely from a number of lines of code standpoint I
don't think we gain anything.

The functions in iterator.c also provide some "boiler-
plate" code which can be copied and adapted for new
iterator implementations (albeit the sizeof function
is missing).

Is that acceptable justification?


----------------------------------------------------------------
イエスかノーかはっきり言ってください。

    _______________________________________________________

Reply to this item at:

  <http://gna.org/bugs/?13802>

_______________________________________________
  Message sent via/by Gna!
  http://gna.org/


_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to