drh / cii

C Interfaces and Implementations

Home Page:http://drh.github.io/cii/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

List Manipulation using pointer to pointers

GoogleCodeExporter opened this issue · comments

Are any particular reason to use pointer to pointers for list manipulation?
For example, in the List interface 
T    List_append(T list, T tail){
  T *p = &list;
  while (*p)
    p = &(*p)->rest;
  *p = tail;

  return list;
}
Writing this function using just pointers like:
T    List_append(T list, T tail){
  T p = list;
  assert(p)
  while (p->rest)
    p = p->rest;
  p->rest = tail;
  return list;
}
Implementing those functions using pointer to pointers is more efficient or you 
just choose that for showing an idiom.
Thanks

Original issue reported on code.google.com by orkunozb...@gmail.com on 31 May 2012 at 7:00

See p. 109 in the book. Your version of List_append does not accept the empty 
list, NULL, as the first argument, which it must per the List interface spec.

Original comment by drhan...@gmail.com on 1 Jun 2012 at 8:17

  • Changed state: Done