Question

if ((!m_pMediaPage->PageLayer() || !m_pMediaPage->LoadState()) &&
     !m_pMediaPage->m_bRequestList)
{
    GetListInfo();
    m_pMediaPage->m_bRequestList = TRUE;
}

GetListInfo() does not get executed when all values are 0.

PageLayer() and LoadState() return ints and m_bRequestList is an int.

Basically rewritten as this:

if ((!0 || !0) && !0)  -or-  if ((1 || 1) && 1)

I can only assume that the values being evaluated by the if statement aren't really as seen by the debugger.

I am using visual studio 2005 and put breakpoints on line 1 & 4 to examine the values and see if it executes into the if statement. I am not sure how else to debug this.

Like I said, each of the 3 values are 0 as viewed by the debugger when at breakpoint 1.

Functions in .h:

int  PageLayer() {return m_iCurrentLayer;} - protected
BOOL LoadState() {return m_bLoadDone;}     - protected

BOOL:

typedef int BOOL;
Was it helpful?

Solution

This conditional statement looks as if it would be executed if all values return from the different functions return zero. If the body of the function isn't executed, I would debug the problem as follows:

  1. Log the values of all functions prior to the if-statement:

    std::cout << "page-layer=" << !m_pMediaPage->PageLayer() << ' '
              << "load-state=" << !m_pMediaPage->LoadState() << ' '
              << "request-list=" << !m_pMediaPage->m_bRequestList << '\n';
    

    Yes, the debugger should show these values as well but I have great faith in the values being printed to be the values actually evaluated.

  2. If that doesn't give the necessary insight into what goes wrong, I would start breaking down the condition into separate parts and verify success at each level, e.g.:

    if (!m_pMediaPage->PageLAyer()) {
        std::cout << "page-layer is not set\n";\
    }
    if (!m_pMediaPAge->LoadState()) {
        std::cout << "load-state is not set\n";
    ...
    
  3. If this still doesn't give any insight, I'd start suspecting that the functions return funny values and I would verify that the different results are funny values and I would start looking at the output after preprocesing using the -E option.

OTHER TIPS

You tagged the question as VS2005; do you have all relevant service packs installed to ensure you aren't running into some long-fixed compiler issue?

Secondly, the functions you've listed appear to be very simple setters (you might want to make them const, although that is unrelated to your problem).

You're stepping thru with the debugger, it might therefore be valuable to check your assertion that they are all zero:

bool plCond = (m_pMediaPage->PageLayer());
bool lsCond = (m_pMediaPage->LoadState());
bool rlCond = (m_pMediaPage->m_bRequestList);
bool getListInfoCond = ((!cond1 || !cond2) && !cond3);

if (getListInfoCond)
{
    GetListInfo();
    m_pMediaPage->m_bRequestList = TRUE;
}

If this fixes the problem, you either have a heisenbug or a stack/memory stomp.

If this doesn't fix the problem, it may home in on the cause.

If this DOES fix the problem, you may want to consult the assembly for the code and see if you have somehow tripped a compiler bug.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top