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

  • Home
  • SEARCH
  • 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 7436203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:12:04+00:00 2026-05-29T10:12:04+00:00

I’m (trying) to write some (working) C++ in an ObjC project :-) The C++

  • 0

I’m (trying) to write some (working) C++ in an ObjC project 🙂 The C++ library (Box2D) provides me with a b2Fixture class which has a “user data” property for coders to store whathever is relevant to them.

In my case, it simply has to store an integer. From my main program in ObjC, one is to cast the integer to void*:

headFixture->SetUserData( (void*) 10 );

In a utility method on the C++ side of the program, I would like to compare the user data to a given integer (i.e. they’re constants, 10 = solid ground, 11 = platform, etc.).

First comparison uses (void*) which refuses to compile. Found on SO a different approach, like illustrated by the second comparison which uses *( (intptr_t *) … ). That one compiles, but it sends EXC_BAD_ACCESS:

bool AbstractContactListener::contactContainsType(JRContact contact, int type){

    if (( type == ( (void *) contact.fixtureA->GetUserData() )) ||
        ( type == *( (intptr_t *) contact.fixtureB->GetUserData() ))
        ) {
        return true;
    }

    return false;
}

I’m running out of ideas to approach this issue.
Please help 🙂
Thanks!
J.

EDIT/SOLUTION:

bool AbstractContactListener::contactContainsType(JRContact contact, int type){

    if (( type == (intptr_t) contact.fixtureA->GetUserData() ) ||
        ( type == (intptr_t) contact.fixtureB->GetUserData() )
        ) {
        return true;
    };

    return false;
}

This one worked for me!

  • 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-29T10:12:05+00:00Added an answer on May 29, 2026 at 10:12 am

    As far as I can see, you just need to cast it back; you need to use an integer type that’s guaranteed to be the same size as a pointer to cast via or the compiler may error out;

    #include <stdint.h>
    
    if(type == (intptr_t)(contact.fixtureA->GetUserData())) {
    

    There is one caveat though, as far as I know, the cast int to void* and back is not guaranteed by the C standard to give back the same value. A safer option may be to just use pointers as they are ment to be used;

    int *value = malloc(sizeof(int));
    *value = 10;
    headFixture->SetUserData( value );
    

    and

    if(type == *(int*)(contact.fixtureA->GetUserData())) {
    

    which shouldn’t tempt any compiler to break your code.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.