Thread: If( false == true ) ... C++ enter in the code

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    10

    If( false == true ) ... C++ enter in the code

    Hi all,

    I'M using VS.net 2003.

    I'm following my code and at some point I found that the test I'M doing seems to not work at all...

    Code:
    	if ( false == true )
    	{
    		m_Type = GL_RGB;
    		m_NbComp = 3;
            }
    It's going in the m_Type = GL_RGB, and so on...

    It's an importer from 3dsmax, one model was working good, I made some changes and it stop working, because of the lines over...

    On the other model, it was the new that was crashing. Both are crashing around almost the same code, maybe the error is linked.

    Here's the code before my function :

    Code:
    //In the main
    	char* ImportFileName = "gob.amd";
    	printf("%s\n",ImportFileName);
    
    	if( data.m_Modele.Creer(ImportFileName) )
    
    .
    .
    .
    
    // In the m_Modele.Creer Function
    			if (Withalpha)
    			{
    				monomat->m_Tex = new Texture(TextureName,TexAlphaName,false,true);
    			}
    			else
    			{
    				monomat->m_Tex = new Texture(TextureName,true);
    			}
    
    //
    Texture::Texture(const char * File, Boolean GenID)
    : m_Type(0), m_NbComp(0), m_Height(0), m_Width(0), m_ID(-1), m_Texels(NULL)
    {
    	Creer(File,GenID);
    }
    
    //Now the place that it is crashing
    void Texture::Creer(const char * File, Boolean GenID)
    {
    	if (m_Type)
    		Detruire();
    
    	BMP_24bits BMP;
    	bool loadOk = LoadBMP(BMP,File);
    
    	loadOk = false;
    
    	if ( loadOk ) // false == true is entering here
    	{
    		m_Type = GL_RGB;
    		m_NbComp = 3;
    .
    .
    .
    }
    
    //This function return false because file dosen't exist.
    Boolean LoadBMP(BMP_24bits & BMP, const char * BMPFileName)
    {
    	FILE			*fichier;
    	unsigned char	Header[0x36];
    	unsigned int	DataPos,DataSize;
    	int				Components;
    	long			NbPixels;
    	int				rest,i,offset;
    	unsigned int	linesize;
    	
    //Read file and header
    	fichier = fopen(BMPFileName,"rb");if (!fichier) return false;
     .
     .
     .
    }
    I don't know what to search in the MSDN, this bug is too weird!

    By the way, I've rebuild all my code just to be sure that it wasn't a bad compilation problem.

    Thanx for the help!
    Last edited by bibiteinfo; 02-06-2006 at 12:07 PM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Use the debugger to check the value of loadOk. Make sure it is set to false when you think it is and watch it as you step through to see if some other code modifies it accidentally.

    Also note that LoadBMP returns a Boolean (whatever that is), but loadOk is a bool that gets its value. Perhaps a Boolean and a bool are not compatible.

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    10
    I'Ve found my error, damn stupid ... I change the code in my lib, but I didn't recompile the lib so I used the old version...

    ... Thanx daved for the help

  4. #4
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    Sorry, I am asking it for myself.
    Code:
    if ( false == true )
    	{
    		...
                    }
    What does it mean? It will never enter the block.

    [EDITED]
    Last edited by siavoshkc; 02-06-2006 at 04:55 PM.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    It should never enter the block. The expression false == true is false because false does not equal true.

  6. #6
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    Sorry I knew I just typed wrongly
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I don't think the OP was using that code exactly. I think he or she expected the variable to be false and was confused by the code inside the block was being executed.

  8. #8
    Registered User
    Join Date
    Feb 2006
    Posts
    10
    Ok I didn't explain well why it was entering the block.

    I have a library (.lib) and I made a change in a .cpp of this library in the program that I show the code. The thing that is happening during debugguing time is that the compiler just show that it is on line 382 and after on line 384, no matter if the .cpp has been changed, it's reading the library code, BUT show the .cpp code!!

    So before recompiling my library ode, I had no if( false == true ) so the compiler just read the instructions that were there before!! This is why it was executing the code inside my false condition.
    Last edited by bibiteinfo; 02-07-2006 at 01:57 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. non-lvalue error
    By zlb12 in forum C Programming
    Replies: 1
    Last Post: 04-17-2009, 10:43 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. BIG problem. How do I find a bug in so much code?
    By Yarin in forum C++ Programming
    Replies: 44
    Last Post: 01-31-2008, 12:39 PM
  4. One quick question...
    By Kross7 in forum C++ Programming
    Replies: 10
    Last Post: 04-13-2007, 09:50 PM
  5. C++ FTP class won't work
    By lord mazdak in forum C++ Programming
    Replies: 8
    Last Post: 12-18-2005, 07:57 AM