Thread: How do I test for this output: CDCDCDCD?

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    19

    Question How do I test for this output: CDCDCDCD?

    Hi all!

    I'm using Visual studio, and have been working on a method for a while now.
    The problem is that I'm testing if an entrance in an array have the value NULL. But when I write the value out on a .txt it says CDCDCDCD instead of NULL. Then how do I test for this value?
    Simple doing: if(... == CDCDCDCD) does not work :-/

    Best regards
    Animation :-)

  2. #2
    Registered User inequity's Avatar
    Join Date
    Nov 2010
    Location
    Seattle, Washington
    Posts
    59
    Microsoft Visual C++ Tips and Tricks

    Check that out.

    Memory Values
    If you're using the debug heap, memory is initialized and cleared with special values. Typically MFC automatically adds something like the following to your .cpp files to enable it:

    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif

    You can find information on using the debug heap here. Microsoft defines some of the magic values here.

    While using the debug heap, you'll see the values:
    Value Usage
    0xCDCDCDCD Allocated in heap, but not initialized
    0xDDDDDDDD Released heap memory.
    0xFDFDFDFD "NoMansLand" fences automatically placed at boundary of heap memory. Should never be overwritten. If you do overwrite one, you're probably walking off the end of an array.
    0xCCCCCCCC Allocated on stack, but not initialized
    So this means that your array was allocated on the heap, but hasn't been initialized. Instead of just being full of completely garbage values, Visual Studio fills it with 0xCDCDCDCD.
    It's important to note that this is NOT the series of characters "CDCDCDCD", but a hex value, 0xCDCDCDCD.

    If you want to test for NULL, you'll have to go through the array and initialize it to NULL after you create it, or use something like ZeroMemory().
    However, testing for CDCDCDCD will not help you out at all.

    It would be helpful if you could try to explain what you're trying to accomplish with this

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I would initialize your arrays or whatever. It sounds like the debugger is giving your uninitialized array (or whatever this really is) a predictable value by default instead of random garbage. That's a problem since if you left it alone, at release, you're basically using an uninitialized value. If you want to test against NULL then make it so the values are either NULL or something, not uninitialized randomness.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    19
    Hi again,

    I have an array called IDMap[][] which i initially fill up with NULL's. Then have a nother array: HRList[8] which is the filled up with values from IDMap[][].
    And since IDMap[][] is initially just NULL's, I thought that all the values would start out to be NULL in all entrances of HRList[], but it is not :-(
    The values in HRList[] is then this uninitialized stuff CDCDCDCD that you describe.

    I have also tried to initialize HRList[] as well but the problem lies in transfering the values from IDMap[][] to HRList[], as the value in IDMap[][] is 00000000 and in HRLst[] is CDCDCDCD (EDIT: The value is CDCDCDCD in HRList[] after filling it with values from IDMap[][])

    Best Regards
    Animation

  5. #5
    Registered User inequity's Avatar
    Join Date
    Nov 2010
    Location
    Seattle, Washington
    Posts
    59
    Can you post the code?

  6. #6
    Registered User
    Join Date
    Mar 2011
    Posts
    19
    The IDMap:
    Code:
    IDMap::IDMap(Landscape * L)
    {
    	maxx=L->SupplySimAreaWidth()/10;
    	maxy=L->SupplySimAreaHeight()/10;
    	m_TheMap = new TAnimal*[ (maxx)*(maxy) ];
    	for (int y=0; y<(maxx); y++)
    	{
    		for (int x=0; x<(maxy); x++)
    		{
    			SetMapValue((x/10),(y/10),NULL);
    		}
    	}
    }
    Part of the class Cat:
    Code:
    ...
    if(m_objType == cob_Male || m_objType == cob_NeuMale)
    	{
    		HRList[0] = m_OurPopulationManager->MaleHomeRangeMap->GetMapValue(m_Location_x / 10, evaluate_y_Down);
    		HRList[1] = m_OurPopulationManager->MaleHomeRangeMap->GetMapValue(evaluate_x_Up, evaluate_y_Down);
    		HRList[2] = m_OurPopulationManager->MaleHomeRangeMap->GetMapValue(evaluate_x_Up, m_Location_y / 10);
    		HRList[3] = m_OurPopulationManager->MaleHomeRangeMap->GetMapValue(evaluate_x_Up, evaluate_y_Up);
    		HRList[4] = m_OurPopulationManager->MaleHomeRangeMap->GetMapValue(m_Location_x / 10, evaluate_y_Up);
    		HRList[5] = m_OurPopulationManager->MaleHomeRangeMap->GetMapValue(evaluate_x_Down, evaluate_y_Up);
    		HRList[6] = m_OurPopulationManager->MaleHomeRangeMap->GetMapValue(evaluate_x_Down, m_Location_y / 10);
    		HRList[7] = m_OurPopulationManager->MaleHomeRangeMap->GetMapValue(evaluate_x_Up, evaluate_y_Down);
    		
    		for(int j = 0; j < 8; j++)
    		{
    			if(HRList[j] != NULL && HRList[j] != this)
    			{
    				//QualityScoreArray[j] -= 2;
    			}
    		}
    	}
    	else
    	{
    		HRList[0] = m_OurPopulationManager->FemaleHomeRangeMap->GetMapValue(m_Location_x / 10, evaluate_y_Down);
    		HRList[1] = m_OurPopulationManager->FemaleHomeRangeMap->GetMapValue(evaluate_x_Up, evaluate_y_Down);
    		HRList[2] = m_OurPopulationManager->FemaleHomeRangeMap->GetMapValue(evaluate_x_Up, m_Location_y / 10);
    		HRList[3] = m_OurPopulationManager->FemaleHomeRangeMap->GetMapValue(evaluate_x_Up, evaluate_y_Up);
    		HRList[4] = m_OurPopulationManager->FemaleHomeRangeMap->GetMapValue(m_Location_x / 10, evaluate_y_Up);
    		HRList[5] = m_OurPopulationManager->FemaleHomeRangeMap->GetMapValue(evaluate_x_Down, evaluate_y_Up);
    		HRList[6] = m_OurPopulationManager->FemaleHomeRangeMap->GetMapValue(evaluate_x_Down, m_Location_y / 10);
    		HRList[7] = m_OurPopulationManager->FemaleHomeRangeMap->GetMapValue(evaluate_x_Up, evaluate_y_Down);
    
    		for(int j = 0; j < 8; j++)
    		{
    			if(HRList[j] != NULL && HRList[j] != this)
    			{
    				//QualityScoreArray[j] -= 2;
    			}
    		}
    	}
    ...
    So the problem is that it goes in the if(HRList[j] != NULL && HRList[j] != this) and subtracts 2. Because HRList[j] is not NULL but this CDCDCDCD

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    It's quite simple, the 0xCDCD pattern tells you you didn't initialise whatever it is you're trying to use.
    So go back and fix the code rather than trying to test for this magic pattern.

    Because as soon as you change from "Debug" to "Release", you will no longer get a nice predictable 0xCDCD "uninitialised" value, but instead you'll get truly random "uninitialised" value instead.
    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
    Mar 2011
    Posts
    19
    Quote Originally Posted by Salem View Post
    It's quite simple, the 0xCDCD pattern tells you you didn't initialise whatever it is you're trying to use.
    So go back and fix the code rather than trying to test for this magic pattern.

    Because as soon as you change from "Debug" to "Release", you will no longer get a nice predictable 0xCDCD "uninitialised" value, but instead you'll get truly random "uninitialised" value instead.
    But I have initialized the values in IDMap as you can see now. But I don't understand why I can't say:
    Code:
    HRList[0] = m_OurPopulationManager->FemaleHomeRangeMap->GetMapValue(m_Location_x / 10, evaluate_y_Down);
    This does not give the value NULL in HRList[0] but an uninitialized value.

    EDIT: Female and MaleHomeRangeMaps is IDMaps:
    Code:
    FemaleHomeRangeMap = new IDMap(p_L);
    Last edited by animation; 04-27-2011 at 04:59 AM.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > But I have initialized the values in IDMap as you can see now
    And are you getting 0xCD's in places you don't expect?
    If you are, then you're still missing something.
    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
    Registered User
    Join Date
    Mar 2011
    Posts
    19
    Quote Originally Posted by Salem View Post
    > But I have initialized the values in IDMap as you can see now
    And are you getting 0xCD's in places you don't expect?
    If you are, then you're still missing something.
    Ohhh! Thanks Salem, have only initialized 1/10 of the IDMap arrays :-/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ overlapping output and adding extensions to output files
    By lordmorgul in forum Linux Programming
    Replies: 9
    Last Post: 05-11-2010, 08:26 AM
  2. terminal output not showing output properly
    By stanlvw in forum C Programming
    Replies: 13
    Last Post: 11-19-2007, 10:46 PM
  3. Test at http://www.artlogic.com/careers/test.html
    By zMan in forum C++ Programming
    Replies: 6
    Last Post: 07-15-2003, 06:11 AM
  4. Replies: 3
    Last Post: 02-19-2003, 08:34 PM