Skip to content

Commit

Permalink
doc: Some minor doc cleanup for new data structures
Browse files Browse the repository at this point in the history
Noticed during attempts at usage that the documentation
needed a couple small updates:

1) Tell the user which header to include
2) Some functions want the address of the data structure

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
  • Loading branch information
donaldsharp committed May 2, 2019
1 parent 5390986 commit 820b3b6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions doc/developer/lists.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ The common setup pattern will look like this:

.. code-block:: c
#include <typesafe.h>
PREDECL_XXX(Z)
struct item {
int otherdata;
Expand Down Expand Up @@ -159,26 +161,26 @@ Common iteration macros

The following iteration macros work across all data structures:

.. c:function:: for_each(Z, head, item)
.. c:function:: for_each(Z, &head, item)
Equivalent to:

.. code-block:: c
for (item = Z_first(head); item; item = Z_next(head, item))
for (item = Z_first(&head); item; item = Z_next(&head, item))
Note that this will fail if the list is modified while being iterated
over.

.. c:function:: for_each_safe(Z, head, item)
.. c:function:: for_each_safe(Z, &head, item)
Same as the previous, but the next element is pre-loaded into a "hidden"
variable (named ``Z_safe``.) Equivalent to:

.. code-block:: c
for (item = Z_first(head); item; item = next) {
next = Z_next_safe(head, item);
for (item = Z_first(&head); item; item = next) {
next = Z_next_safe(&head, item);
...
}
Expand All @@ -189,15 +191,15 @@ The following iteration macros work across all data structures:
tables is resized while iterating. This will cause items to be
skipped or iterated over twice.

.. c:function:: for_each_from(Z, head, item, from)
.. c:function:: for_each_from(Z, &head, item, from)
Iterates over the list, starting at item ``from``. This variant is "safe"
as in the previous macro. Equivalent to:

.. code-block:: c
for (item = from; item; item = from) {
from = Z_next_safe(head, item);
from = Z_next_safe(&head, item);
...
}
Expand Down

0 comments on commit 820b3b6

Please sign in to comment.