Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble with Strings
    primarykey
    data
    text
    <p>I am currently debugging a sizable program. When I come to the following line of code:</p> <pre><code>value-&gt;binary_string = value_it-&gt;binary_string.substr(range-&gt;msb-&gt;value, range-&gt;size); </code></pre> <p>The program does not behave correctly. Here value is a pointer to a struct with a member named binary_string with type std::string. When I reach this line while debugging, I see that:</p> <pre><code>value_it-&gt;binary_string = "00000000000000000000000000000111" range-&gt;msb-&gt;value = 0 range-&gt;size = 32 </code></pre> <p>After this line of code executes, value->binary_string is empty! I have even changed the line to</p> <pre><code>value-&gt;binary_string = value_it-&gt;binary_string </code></pre> <p>and it still fails!</p> <p>When I reach this line while debugging, my program is using about 100 Mb of memory, so I don't think it is a memory issue (though I am running Valgrind as we speak to verify this). I am using Ubuntu 11.10, g++-4.6 and libstdc++6.</p> <p>Has anyone encountered something like this before? I have no idea why my strings aren't working!</p> <p>Thanks,</p> <p>Sam</p> <p>EDIT1:</p> <p>The type of value is NumberInst, defined below:</p> <pre><code>typedef std::string String; struct NumberInst { unsigned size; bool signed_; String binary_string; bool valid; unsigned value; NumberInst(); }; </code></pre> <p>EDIT2:</p> <p>It looks like I've narrowed down the search a little bit. While debugging, I tried a few print commands:</p> <pre><code>print value_it-&gt;binary_string "00000000000000000000000000000111" print value_it-&gt;binary_string[31] '1' print value_it-&gt;binary_string.substr(0, String::npos) "" print value_it-&gt;binary_string.substr(0, 1) "" </code></pre> <p>It seems that substr is not working properly in this context. However, when I tested substr in my main function, it seemed to work okay.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload