Thread: Conflicting boolean values

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by jdodle
    does it define any behavior for values other than this? if not then what happens when it is declared but not initialized? can it have some other value. Im thinking that Xcode interprets these "other" values in an undefined manner.
    The C++ standard explicitly notes:
    Quote Originally Posted by C++11 Clause 3.9.1 Note 47
    Using a bool value in ways described by this International Standard as “undefined,” such as by examining the value of an uninitialized automatic object, might cause it to behave as if it is neither true nor false.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Quote Originally Posted by laserlight View Post
    The C++ standard explicitly notes:
    That's a good point (love those standard quotes!). I didn't consider that the implementation is allowed to assume that the bool is properly initialized. I was thinking of how an integer is handled in a boolean context where 0 is false and absolutely any other number is true. But with a bool, it should always be 1 for true, I guess, so an impl is allowed to, for example, simply test the low bit to determine truth or falsity. Apparently the debugger is doing things differently than the ?: operator, yielding different results. Still, it would be better if the debugger indicated a bad value.

  3. #18
    Registered User
    Join Date
    Jan 2016
    Posts
    52
    Every attempt I have made to reproduce the code in an isolated example has failed so I figured the best bet was to just post my full code.

    I didn't realize it was calling static functions or members of mat_net at this point, you can comment out anything thing that uses it. It will disable several functionalities of the program but the bug producing aspect will still be there.

    I apologize for the uncommented, large, and overall awful code, I wrote this whole thing in about a day or two for a school project and I have to focus on final exams now so I don't really have time to clean it up. Not to mention I got rid of the bug already. So this is more for community curiosity than anything else.

    Also, with mat_net.cpp and mat_net.hpp I compile with no warnings and no errors. If you remove all the code reliant on mat_net and compile with c++11 you should get similar results.

  4. #19
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Every attempt I have made to reproduce the code in an isolated example has failed so I figured the best bet was to just post my full code.
    This is actually incredibly telling...

  5. #20
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Quote Originally Posted by MutantJohn View Post
    This is actually incredibly telling...
    Do tell...

  6. #21
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    It means you have uncontrolled action at a distance, most likely.

  7. #22
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Or rearranging the code puts different values in uninitialized variables.

  8. #23
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Quote Originally Posted by algorism View Post
    Or rearranging the code puts different values in uninitialized variables.
    *shudders*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Negating Boolean Values
    By Khabz in forum C++ Programming
    Replies: 2
    Last Post: 03-22-2013, 08:40 AM
  2. Conflicting functions - Help.
    By Livnat in forum C Programming
    Replies: 8
    Last Post: 07-13-2008, 07:25 PM
  3. Boolean Values
    By guitarman32 in forum C++ Programming
    Replies: 17
    Last Post: 04-06-2006, 12:54 PM
  4. conflicting types for...
    By dudinka in forum C Programming
    Replies: 3
    Last Post: 05-14-2005, 07:03 AM
  5. Replies: 4
    Last Post: 04-02-2004, 07:30 PM

Tags for this Thread