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 );
}

Recommended Answers

All 3 Replies

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.

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.