This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Annoying warning


| It would be better to either remove the 'inline' or to rewrite the
| function into a form that can be inlined (tail recursion):
| 
| inline int __black_count(__rb_tree_node_base* node, __rb_tree_node_base* root,
| 			 int black_parent)
| {
|     if (node == 0)
| 	return black_parent;
|     else {
|         int bc = (node->color == __rb_tree_black);
| 	if (node == root)
| 	    return bc + black_parent;
| 	else
| 	    return __black_count(node->parent, root, bc);
|     }
| }

I think need to return __black_count(node->parent, root, bc + black_parent) there.

On the other hand, it doesn't seem to increase readability to me.
I'd get rid of the recursion completely and write something like this:

inline int __black_count(__rb_tree_node_base* node, __rb_tree_node_base* root)
{
  int count = 0;
  for (; node; node = node->parent)
  {
    if (node->color == __rb_tree_black)
      ++count;
    if (node == root)
      break;
  }
  return count;
}

Perhaps you can forward this to the maintainers of the STL egcs is using?

-- 
 Carlo Wood  <carlo@runaway.xs4all.nl>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]