Strange if-statements execution

This is a discussion on Strange if-statements execution within the C++ Programming forums, part of the General Programming Boards category; Donīt really know if I should post this here or in the game-programming board. But I make a try here ...

  1. #1
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343

    Strange if-statements execution

    Donīt really know if I should post this here or in the game-programming board. But I make a try here and if it is wrong a mod can move it to gp.board. Anyway Im trying to code a simple(lame?) tetris clone using the glut-library.
    I have a gridsystem(10X20) that indicates if a block is occupied or not. The problem is that some if-statemets are/"are not" evaluated, e.i

    Code:
    ...
    ...
    //DEBUG DEBUG DEBUG DEBUG
    if (grid.moccupied[x1][y1-1] == true)
    	std::cout << "UNDERLYING block is occupied(Block 1)" << std::endl << std::endl;
    if (grid.moccupied[x2][y2-1] == true)
    	std::cout << "UNDERLYING block is occupied(Block 2)" << std::endl << std::endl;
    if (grid.moccupied[x3][y3-1] == true)
    	std::cout << "UNDERLYING block is occupied(Block 3)" << std::endl << std::endl;
    if (grid.moccupied[x4][y4-1] == true)
    	std::cout << "UNDERLYING block is occupied(Block 4)" << std::endl << std::endl;
    
    if ((grid.moccupied[x1][y1-1] == true) || (grid.moccupied[x2][y2-1] == true) 
    || (grid.moccupied[x3][y3-1] == true) || (grid.moccupied[x4][x4-1] == true))
    			std::cout << "UNDERLYING BLOCK IS OCCUPIED" << std::endl;
    ...
    ...
    How is it possible that the string "UNDERLYING BLOCK IS OCCUPIED" is printed to the screen and at the same time none of the preceding if-statements prints nothing??
    01000111011011110110111101100100 011101000110100001101001011011100110011101110011 01100100011011110110111001110100 01100011011011110110110101100101 01100101011000010111100101110011 0110100101101110 01101100011010010110011001100101
    Good things donīt come easy in life!!!

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    You're not testing the same thing.

    >>> (grid.moccupied[x4][x4-1] == true)

    There for example? y?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    OMG
    I donīt know if I should laugh or cry?. Of course you are right adrianxw. Iīve been looking for this bug for a week now.
    Tip: Buy a bigger screen so you can actually se the whole if-statement and GET SOME SLEEP.

    Anyway thx adrianxw
    01000111011011110110111101100100 011101000110100001101001011011100110011101110011 01100100011011110110111001110100 01100011011011110110110101100101 01100101011000010111100101110011 0110100101101110 01101100011010010110011001100101
    Good things donīt come easy in life!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 03:09 AM
  2. Execution Time - Rijandael encryption
    By gamer4life687 in forum C++ Programming
    Replies: 5
    Last Post: 09-20-2008, 09:25 PM
  3. newbie question - if statements without conditions
    By c_h in forum C++ Programming
    Replies: 2
    Last Post: 07-18-2008, 10:42 AM
  4. Efficiency of case statements
    By Yasir_Malik in forum C Programming
    Replies: 26
    Last Post: 05-23-2006, 11:36 AM
  5. Strange results using dnsapi and windns
    By Niara in forum Networking/Device Communication
    Replies: 3
    Last Post: 08-13-2005, 10:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21