[Dbc-talk] Checking a linked list
Valster Nico-anv009
nvalster at motorola.com
Fri Sep 2 05:11:47 EDT 2005
Is there a way to check a linked list build from elements defined as:
struct MDU_DESCRIPTOR_S {
MDU_DESCRIPTOR_T* next; //chain pointer
UINT8* dat; //buffer pointer
UINT16 len; //length of data in buffer
};
I want to traverse a list via the next pointer till I reach NULL and verify that all dat pointers are non-NULL and all len values are non-zero. Something along the line of:
MDU_DESCRIPTOR_T *p;
while ( p ) {
assert( dat );
assert( len );
p = p->next;
}
Although the forall idiom suggests it can usually replace the while iterator, I have no idea how to tackle the problem.
Is there a way or should I transform above C-code to a helper-routine which returns true or false depending on whether an assert triggered or not and then use that inside a pre-condition e.g. something like
pre ## list error ## : rtn(p) == TRUE
To me this feels like a kludge
-------------------------------------------------------------------------------------------------------------------
Nico Valster E-Mail: nvalster at motorola.com Phone: +31 30 6001642
--------------------------------------------------------------------------------------------------------------------
More information about the Dbc-talk
mailing list