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 822247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:46:18+00:00 2026-05-15T02:46:18+00:00

I am mixing some C and C++ libraries and have only a single pointer

  • 0

I am mixing some C and C++ libraries and have only a single pointer available to do some work in a callback function. All I need to do is iterate through a vector. Here’s a simplified, untested example:


bool call_back(void* data){
  done=...
  if (!done) cout << *data++ << endl;
  return done;
}

Note that this function is in an extern "C" block in C++. call_back will be called until true is returned. I want it to cout the next element each time it’s called. data is a pointer to something that I can pass from elsewhere in the code (an iterator in the above example, but can be anything). Something from data will likely be used to calculate done. I see two obvious options to give to data:

  1. Have data point to my vector.
  2. Have data point to an iterator of my vector.

I can’t use an iterator without having the .end() method available, right? I can’t use a vector alone (unless maybe I start removing its data). I could make a struct with both vector and iterator, but is there a better way? What would you do?

  • 1 1 Answer
  • 1 View
  • 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-05-15T02:46:18+00:00Added an answer on May 15, 2026 at 2:46 am

    Why not have data point to a structure with all the information you need.

    The point about the old “C” style callbacks is that a void* can point to any object. Your callback function knows what the type is, but it can be anything.

    typedef struct Plop
    {
        std::vector<int>::iterator begin;
        std::vector<int>::iterator end;
    } Plop;
    
    bool call_back(void* data)
    {
        // Or static_cast<> for the pedantic.
        // I like reinterpret_cast<> because it is a clue to humans that this is dangerious
        // and as long as the object was originally a Plop* pointer it is guaranteed to work.
        Plop*   info = reinterpret_cast<Plop*>(data);
    
        bool    done= info.begin == info.end;
    
        if (!done) cout << *data++ << endl;
        return done;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read some posts on here about not mixing parameters when passing into
I am having some trouble mixing PHP with XML. I currently have a PHP
i have a doubt on concept i think i am mixing some stuff. I
i have a doubt on concept i think i am mixing some stuff. I
Need some help with getting the listener to work with my listview. My activity
I have problem mixing pattern match and curdate() function. Below is the table structure,
I'm working with an old sql server 2000 database, mixing some of it's information
I am having trouble mixing c# functions with conditions in Linq-To-SQL suppose i have
I have been using SmartGWT but have run into trouble mixing SmartGWT with other
We're using Jon Skeet's proto-csharp-port, and I'm running into some difficulties when mixing it

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.