Thread: compiler bug or brain bug?

  1. #1
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428

    compiler bug or brain bug?

    Ok my compiler gives me a warning "bool roof() will always evaluate as true"

    Code:
    bool roof()
    {
         if((xxx+20) >= 182 && xxx <= 222 && (yyy-200) <= 301)
         {
           yyy=302;
           drawlvla();
           return true;
         }
         else
           return false;
    }
    I don't understand this if xxx = 0; then it should return false. Because it would not be greater than or equal to 182. I understand if I used or statements this would evaluate as true since xxx would always be less than 222 or greater than 182. I have the newest version of dev c++ is this a compiler bug, or is my brain bugged? Thank you for your time.

  2. #2
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    OK sorry the moment after I post I figure out the answer. When recalling the bool function I forgot to use () if(!roof) rather than if(!roof()) I should have waited 10 more minutes before posting.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Post the smallest and simplest compilable program that demonstrates the warning.

    EDIT:
    Ah.
    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

  4. #4
    C++11 User Tux0r's Avatar
    Join Date
    Nov 2008
    Location
    Sweden
    Posts
    135
    Turn up your warnings and those time crunching problems will disappear like magic!

  5. #5
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    I'm sorry tuxor what do you mean by turn up your warnings?

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Turn up your warnings and those time crunching problems will disappear like magic!
    Sounds like warning were already enabled.
    Ok my compiler gives me a warning "bool roof() will always evaluate as true"

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well what types are xxx and yyy

    I seriously doubt that you really have variables called xxx and yyy, and that you've paraphrased your problem into something which is not the same.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Quote Originally Posted by Salem View Post
    Well what types are xxx and yyy

    I seriously doubt that you really have variables called xxx and yyy, and that you've paraphrased your problem into something which is not the same.
    He already solved the problem...

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Hmpf
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #10
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    Yea I'm sorry I wish there was I way I could delete the post to not waste people's time.

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Your experiences will help others with the same problem. Hopefully.
    Don't worry.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. lcc win32 compiler download problems
    By GanglyLamb in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 08-01-2004, 07:39 PM
  2. OpenScript2.0 Compiler
    By jverkoey in forum C++ Programming
    Replies: 3
    Last Post: 10-30-2003, 01:52 PM
  3. Compiler or OS bug??
    By Frantic in forum C++ Programming
    Replies: 6
    Last Post: 05-20-2003, 11:17 PM
  4. compiler bug ?
    By Spectrum48k in forum C++ Programming
    Replies: 5
    Last Post: 02-25-2003, 09:39 PM
  5. Special Compiler for win app's
    By Unregistered in forum Windows Programming
    Replies: 19
    Last Post: 04-26-2002, 03:52 PM