0

i half understand this code, just wondering if anybody could give me helpful tips/hints about understanding the difference between these two functions

extern status traverse( list L, status ( *p_func_f )() ){

  if( empty_list ( L ) ) return ( OK ) ;

  if( ( *p_func_f ) ( DATA( L ) ) == ERROR ) return ERROR ;

  else

    return( traverse( NEXT(L), p_func_f ) );
}

extern list list_iterator( list L, list lastreturn ) {

  return ( lastreturn == NULL ) ? L : NEXT( lastreturn );
}
2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Ancient Dragon
0

1) both functions use the extern keyword incorrectly. extern means it is coded in some other translation unit, which the code you posted is certainly not.

2) can't tell just what the difference is because I don't know what the macro NEXT does. My guess is that it is causing recursion.

0

both functions are found in list.c, defined in list.h and used in main.c

NEXT and DATA are both shortcuts for saying L -> next or L -> datapointer

0

The first function is recursive, while the second is not. For the second function to work you need other code to call it repetedly.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.