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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:14:34+00:00 2026-06-07T11:14:34+00:00

I’m facing a very very strange behavior my application. I’m going to describe my

  • 0

I’m facing a very very strange behavior my application.

I’m going to describe my situation and then explain what is going wrong.

Situation

I have a method with a signature like this:

const StructureDef *getStructure(const std::string &theme, int index);

And I call it in this piece of code:

const StructureDef *sDef = 0;
do 
{
    sDef = ss->getStructure(theme, rand() % ss->availableStructureCount());
} while (!sDef);

I’m using this do-while structure, because the return value of the getStructure method might be NULL, depending on the combination of theme and index. So basically, what it does is asking random structures until we get a valid one. (If you want to know the detail, take a look at the screenshots.)

The method iterates over a std::vector<StructureDef> using it’s ::iterator. And for each StructureDef, it checks if the structure belongs to that theme. If so, post-increase the counter and check if it is equal to the requested index. Like this:

// inside the loop
if (i++ == index)

When this if succeeds, the current StructureDef * is returned:

return sDef;

What is going wrong

I’m using XCode 4.4 it’s debugger to see step by step what is going on, which is basically gdb.

The method I explained first, find a StructureDef * that matches my needs. So it returns that pointer. Here is a screenshot of the moment just before it is going to return in the debugger:

Return point in the debugger

(The line after the for-loop is simply return 0;)

Here the pointer sDef * points to 0x1d563270, which is where the correct instance of the StructureDef is located.

Next screenshot is what we get in the piece of code where I called that method:

Caller gets wrong address

As you can see, the pointer sDef *, which got the return value of the method, now points to 0x2fe03804. This is not what the method returned at all! I’m thinking that this is pointer points to somewhere on the stack, instead of the heap. (It should be the heap since the std::vector class stores its objects on the heap, right?).

I can’t use Valgrind yet, since I’m on Mac OS X 10.8, which isn’t supported by Valgrind.

I’m totally surprised by this behavior. I can’t see why this is happening… Can it be that my compiler is broken, or is it doing some strange “optimization”?

Thanks in advance!
Martijn


To clarify DeadMG’s comment:

I’m using different themes:

iron
wood
ice

etc…

My identifiers look like this:

iron__downside_touch_and_go
iron__platform__700_65
iron__wall_bang
wood__platform__600_40

etc… What I want to do is pick the structure with a specific index within one theme. So not the index the set of structures of all themes together, but the index of the subset of one theme. Take a look at the piece of code again 🙂


Update!!!

I gave wrong info. The vector is of the type std::vector<StructureDef>!! It stores objects. Not pointers!

So what (I think) I’m doing with the .operator->() call is the same as: &(*it). And it looks like it is working. To me it looked a bit stupid to write & and * after each other.


@Ben Voigt:

Architecture:
enter image description here

Optimisation:
enter image description here

  • 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-07T11:14:36+00:00Added an answer on June 7, 2026 at 11:14 am

    It looked like the debugger I was using (LLDB and not GDB as I though first) did not display the memory values correctly. After switching to GDB, the debugger showed the memory addresses I excepted to see. When I added a print statement like this:

    printf("StructureDef* pointer = %llx\n", (unsigned long long int)(void*) sDef);
    

    it looks like GDB is right. For testing purposes, I switched back to LLDB, and magically it was working correctly as well.

    Maybe, I’m dealing with what this guy wrote: https://stackoverflow.com/a/9709462/155137

    I hope it is a bug in the LLDB debugger. Because, otherwise, I think there is something really broken on my installation.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.