I haven't noticed the 'same variable' thing much under CW, but I see it a
lot with other compilers.  Basically, the optimizer recognizes that there is
no overlap in scope and reuses the same register or stack memory for more
than one variable.  The debugger just reports the memory/register value for
each symbol.

I'm not sure about the other problem, it sounds like a compiler/optimizer
problem, but without seeing the resulting assembly language code it is hard
to tell.  If you can't get the debugger to step on the source line that
generally means that no code was generated.   It might be something stupid,
like the optimizer misunderstanding the declaration line and thinking that
catSelected is -1 and then assuming the comparison is moot.

FWIW, A lot of compilers have trouble with mixing initialized and
un-initialized automatic variables on the same line.  SDS, Keil, and
Greenhill for sure.  Maybe CW...

Good Luck,
-jjf

-----Original Message-----
From: Jeff Allen [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 10, 2000 11:36 AM
To: Palm Developer Forum
Subject: Variable Problems


Here's a small snipit of the code that I'm having a problem with:

----------------------------------------------------------------------------
--------------------
static void UpdateList(Word selectedRecord)
{
      FormPtr pFrm = FrmGetFormPtr(MarksForm);
        ListPtr pLst = (ListPtr)GetObjectPtr(MarksTitleList);
        ListPtr pCatList = (ListPtr)GetObjectPtr(MarksCategoriesList);

        RectangleType lstRect;
        Int lstWidth, textLen, i, j, choicesOffset = 0;
        CharPtr choices;
        Word selectedIndex = -1, catSelected;
        VoidHand recHandle;
        Err error;
        UInt theCategory, recordNum = 0, totalItems, displayedItems = 0;
        Boolean fits;
        CharPtr pTitle = 0;


        catSelected = LstGetSelection(pCatList);

        if (catSelected > 1)
        {
            theCategory = CategoryFind(gDBHandle,
LstGetSelectionText(pCatList,
catSelected));
        } else {
            theCategory = dmAllCategories;
        }

[remaining code omitted]
----------------------------------------------------------------------------
--------------------

Now the problem is happening with the line: if (catSelected > 1)

Common sense tells me that if catSelected == 3, then (3 > 1) is true, so
this expression should evaluate as true.  It doesn't.  Ever.  When I run it
through the debugger, it doesn't even stop on the if statement, it just
skips down to the else block.  One other strange thing that I noticed while
watching the debugger.  When catSelected is assigned, these variables:

        error
        displayedItems
        selectedIndex

all get set to the exact same value, for no apparent reason.  I'm certain
these two issues are related, but I can't for the life of me imagine why
this would be happening.  Any ideas?

-Jeff


-- 
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to