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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:01:24+00:00 2026-06-14T23:01:24+00:00

A very weird case just happened to me – while using the debugger, it

  • 0

A very weird case just happened to me – while using the debugger, it shows me that the value of some boolean variable is true, but when I print it (or do with it any other operation), it behaves as 0 (i.e. false).

What can I do to fix this bug? I’m afraid that this is environmental bug so publishing code-example will be meaningless. (a hidden, annoying memory management bug can’t be the reason, right?), and in this context I want point out that it will surprise me to discover that my environment is not well-configured (I work on this project in this environment for more than a year).

So far I:

  • Double-checked that the compiler doesn’t make any optimization to the code, in my project properties.
  • Tried to re-open visual studio and clean and re-build the project
  • Searched on the web for solutions (didn’t find any).
    I use visual studio 2010 and my programming language is C++

Regarding code-sharing requests:

I’m sorry but I can’t publish the code (my bosses will not be happy to see it run in the web)….If you are able to give some ideas about possible reasons to the problem it will be great, and I will look for clues in the code myself, to check if these reasons really caused the problem. However, just to be clear, here are the few code-lines that struggle me:

    bool dir = getNode(location)->getNext()->getDirection(); //dir is displayed as "true" in the debbuger
    int toPush = (dir == 1) ? 1 : 0; //"toPush" is displayed as "0" in the debbugger
    cout<<dir<<endl; //both output 0.
    cout<<(dir == true)<<endl;

Following your request I’m attaching a screen-shot. Notice the value of “dir” that is deqplayed at the right-buttom of the screen as “true”, and to the program output on the right, that ends with 0 (which correspond to the “cout<< dir” command).

screen shot

  • 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-14T23:01:25+00:00Added an answer on June 14, 2026 at 11:01 pm

    You shouldn’t use the == operator to test a bool value for truth. Any non-zero value is true. You have two cout lines and the last two lines in the console window say 240 and 0. I wrote this to demonstrate what I think is happening:

    #include <iostream>
    
    using namespace std;
    
    static bool getDirection()
    {
        union forceBoolValue
        {
            unsigned int iValue;
            bool bValue;
        };
        forceBoolValue retValue;
        retValue.iValue = 0xFFFFFFFF;
        return retValue.bValue;
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        bool dir = getDirection();  //dir is now 255*, which is non-zero and therefore "true"
        int toPush = (dir == 1) ? 1 : 0;  //dir may be true but it is not one, so toPush is 0
        int toPush2 = dir ? 1 : 0;  //dir is true, so toPush2 is 1
        cout << "Dir: " << dir << endl;
        cout << "toPush: " << toPush << endl;
        cout << "toPush2: " << toPush2 << endl;
        return 0;
    }
    

    A similar thing happens with dir == true where it is probably again testing for the value of one. I have no idea why dir is getting an unusual value in your code (240), but if you remove the comparisons and just test the value (as toPush2 above) it should fix the issue.

    I know you said the toPush line is just to demonstrate the issue, but are you doing comparisons in any of your real code? If so, remove them.

    *dir might not be 255, depends on the size of bool in your environment.

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

Sidebar

Related Questions

This is a very weird problem. My app that runs just fine but somehow
I have encountered a very weird situation in Python. I have a while True:
I have just had a very weird thing happen; I had my login script
Either I'm very tired or something weird is happening that I'm not aware of,
I'm trying to profile my renderer, and I'm seeing some weird profiling behavior that
Now this is going to be a little weird use-case. Maybe someone has some
So I have a very weird problem. I am writing some code in VB.Net
I've got a very weird behavior, in my java (spring) application, I've a case
I've written a small Groovy script that exposes a very weird behaviour. can anyone
I having a very weird problem for my asp project. My project can run

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.