Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8555853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:13:07+00:00 2026-06-11T15:13:07+00:00

I have a tree-traversal API that looks like this treeTraverse(Tree *ptr, (void *) call_back(Tree

  • 0

I have a tree-traversal API that looks like this

treeTraverse(Tree *ptr, (void *) call_back(Tree *ptr));

This API traverses the tree and calls the call back function with each entry. I want to traverse the tree and call a function

myFunc(Tree *ptr, int a, int b)

for every entry on the tree, but as you can see above the call back function only accepts one argument, so registering myFunc() as the call back function wont work. How do I get around this problem.

Rewriting the treeTraverse() API to accept variable arguments would not feasible, as it is a framework API and if I need to change it I would have to get it reviewed by lot of people. Not something I am looking forward to as I only need to implement a very small functionality.

Another way way would be to make the variables ‘a’ & ‘b’ global, so myFunc can access it. but this solution looks very ugly.

Is there any other way around this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:13:09+00:00Added an answer on June 11, 2026 at 3:13 pm

    Making a and b global seems like a reasonable solution, given your circumstances. Be careful, though, it isn’t thread or recursion safe.

    If you could add just a single extra argument to treeTraverse which gets passed to the callback, then you can pass an arbitrary number of extra arguments using a struct:

    void treeTraverse(Tree *ptr,
                      (void *) call_back(Tree *ptr, void *arg),
                      void *call_back_arg);
    struct {
      int a;
      int b;
    } args = {...};
    treeTraverse(ptr, myCallback, &args);
    

    This is a standard feature of most code that uses callbacks. You should insist that it get added to your framework API, it is a much better solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file that looks like this: <?xml version=1.0? encoding=UTF-8 standalone=no?> <dir
I have a tree walker like this: function: ^(FUNCTION_TOK fcname=IDENTIFIER param=functionParameters*){ a_param_arrayList.add(param); } ;
I have an unusual tree array like this: [[0, 1], [1, 2], [2, 3],
I have a hard time with tree traversal, and so avoid it like the
I have a parse tree for my compiler, and i was wondering what traversal
I have tree like following example, where every leaf is object. [1] |--[2] |
I have a binary tree, and pre-order traversal. Here is my tree. 15 /
i have made an binary tree, and im trying to make an postorder traversal.
Let’s say I have table/list like this n=3 in this case, but n can
I'm sorry if this seems like a random question, but I have a database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.