> > During execution, the following occurs during the IDE trace:
> > 1. The subprogram is entered and immediately jumps to the "return
> > builder" statement. (Why?)
> > 2. Then, the function is reentered and code steps are taken - until the
> > "if" statement executes. The logic works as expected with the data
It gets weirder and weirder...
First, I'm not producing (or testing) a Release version, and I have
no non-normal optimizations set. I'm running "vanilla" VS2010 Express,
afaics.
Second, there are other things going that I hadn't mentioned:
1. As I debug, some of the variables in the function don't show up, nor
can I see their values during execution by holding my mouse over them
while the code is being stepped through. (Highly unusual!.) The
variables that don't show are all the scalars (ints and chars), while
the non-scalars do show (and change as code executes).
2. I have tried moving the position of the scalar variables within the
routine, but no change there.
3. I moved the scalars outside of the routine (making them global
<gasp!>), and they show and change, as execution proceeds - as they
should.
4. Also, once these scalars are moved and debug normally, the code runs
through the logic provided (!). (I know that nothing really changes in
terms of the return string, but there's more logic to be added to do
some of that - I'm just working out the logic to handle the data and
expand it as needed.)
Thus, it appears that the problem of code that isn't executed within
the routine is some effect of the scalar data declared and used in the
code (totally odd, in my experience...). I'm at a complete loss to
understand this... 8<{{
Here's my latest code (which as I said is working as I step through
the debugger). <sigh>
#include <string>
#include <sstream>
using std::string;
using std::ostringstream;
int ii, dPos, nn;
char wc;
int ndigit;
int column;
string spellNumber(double value)
{
string digitStr;
ostringstream ossw;
static string builder;
ossw.str(""); // Convert integer portion of value to string
ossw << value, digitStr = ossw.str();
dPos = digitStr.find(".");
if(dPos != string::npos)
digitStr.erase(dPos);
nn = digitStr.length(); // Traverse characters in reverse order
wc = digitStr.back();
for(ii = digitStr.length()-1; ii >= 0; ii--)
{
ndigit = (int)(digitStr.at(ii)-'0');
column = (digitStr.length()-(ii+1));
} // for
// more logic to be added here...
return builder;
}
int main(int argc, char *argv[])
{
string str = spellNumber(123.45);
return EXIT_SUCCESS;
} // main