DOC: Setdflag.c Sample for _CrtSetDbgFlag Missing Tilde (~) (142420)



The information in this article applies to:

  • The C Run-Time (CRT), when used with:
    • Microsoft Visual C++, 32-bit Editions 4.0
    • Microsoft Visual C++, 32-bit Editions 4.1
    • Microsoft Visual C++, 32-bit Enterprise Edition 4.2
    • Microsoft Visual C++, 32-bit Professional Edition 4.2
    • Microsoft Visual C++, 32-bit Enterprise Edition 5.0
    • Microsoft Visual C++, 32-bit Professional Edition 5.0

This article was previously published under Q142420

SUMMARY

The Setdflag.c sample program in the Help under _CrtSetDbgFlag(), contains the following section of code which is missing a tilde (~) character:
/*
* Set the debug-heap flag to no longer keep freed blocks in the
* heap's linked list and turn on Debug type allocations (CLIENT)
*/ 
 tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
 tmpDbgFlag |= _CRTDBG_ALLOC_MEM_DF;
 tmpDbgFlag &= _CRTDBG_DELAY_FREE_MEM_DF;  // This line is wrong
 _CrtSetDbgFlag(tmpDbgFlag);
				
The third line of code should be:
 tmpDbgFlag &= ~_CRTDBG_DELAY_FREE_MEM_DF;
				

MORE INFORMATION

To disable a flag with the _CrtSetDbgFlag() function, you should AND the variable with the bitwise NOT of the bitmask.

Modification Type:MajorLast Reviewed:12/9/2003
Keywords:kbCRT kbdocerr KB142420