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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:21:19+00:00 2026-05-24T06:21:19+00:00

I am having trouble giving a struct value to a C interface for a

  • 0

I am having trouble giving a struct value to a C interface for a queue that manages the queue as a linked list. It holds onto the data as void pointers to allow the interface to manage any data generically. I pass in the value as a pointer reference which is then saved as a void pointer. Later when it is returned I do not know how to cast the void pointer back to the original value.

What do I need to do? Here is the sample struct.

typedef struct MyData {
    int mNumber;
} MyData;

To simplify everything I have created a dummy function that simulates everything in a few lines of code.

void * give_and_go(void *data) {
    void *tmp = data;
    return tmp;
}

You can see it takes in a void pointer, sets it as a local variable and then returns it. Now I need to get the original value back.

MyData inVal;
inVal.mNumber = 100;
void * ptr = give_and_go(&inVal);
MyData outVal; // What converts ptr to the out value?

This is where I am stuck. I am using Xcode and it will not allow me to simply cast ptr to MyData or various alternatives that I have tried.

Any help is appreciated.

  • 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-05-24T06:21:20+00:00Added an answer on May 24, 2026 at 6:21 am

    Cast your void* back to a MyData*, then dereference it.

    MyData *outVal = (MyData*)(ptr);

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

Sidebar

Related Questions

Having trouble with proper regex for RewriteCond RewriteCond %{REQUEST_URI} !^/foo/ Works as expected, that
We're having trouble with an existing ASP.NET Webforms app. It's an app that has
I'm having trouble with some JavaScript that I've written, but only with Internet Explorer
I am having some trouble with Python giving me a result I do not
Hello I'm having trouble figuring this out. I have these structs and classes. struct
I'm having trouble with setting a variable and then giving it the outcome of
I'm having trouble recreating the issue in jsbin without giving away project-specific details (I'm
Hey guys! I am having some trouble with giving an MKAnnotationView an image instead
I'm using nyromodal, and having trouble giving the pop-up window a fixed position relative
I'm having trouble with the Win32 NT headers giving me odd RVA's for import

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.