Hi Jeff, On 11/26/2012 09:01:18 AM Mon, stedfast comcast net wrote: [ snip ]
For example, check this out: typedef struct _ListNode { struct _ListNode *next; int id; } ListNode; ListNode *list, *tail, *node; int i; list = NULL; tail = (ListNode *) &list; for (i = 0; i < 10; i++) { node = malloc (sizeof (ListNode)); node->id = i; tail->next = node; tail = node; } tail->next = NULL;
...or perhaps: ListNode *list, **tail, *node; int i; list = NULL; tail = &list; for (i = 0; i < 10; i++) { node = malloc (sizeof (ListNode)); node->id = i; *tail = node; tail = &node->next; } *tail = NULL; Avoids the cast, so it's more transparent, and avoids dependence on ListNode.next being the first member of the struct; however, the generated code would be identical, so long as in fact ListNode.next is the first member of the struct. (Also, the initial 'list = NULL;' is redundant in both versions, but perhaps still worthwhile.) Best, Peter
Attachment:
pgpUN8nzSjLdc.pgp
Description: PGP signature