开发者

What's such macro for?

开发者 https://www.devze.com 2023-01-19 12:35 出处:网络
#define V开发者_StackOverflow社区alidateReadPtr(p,cb) 0 I can\'t think of a use case for this kind of macro,what about you?I can only find the ValidateReadPtr() macro in the wxdebug.h header for the
#define V开发者_StackOverflow社区alidateReadPtr(p,cb) 0

I can't think of a use case for this kind of macro,what about you?


I can only find the ValidateReadPtr() macro in the wxdebug.h header for the Windows Mobile SDK (even though MSDN indicates it's part of the DirectShow APIs).

In wxdebug.h it's defined as:

#define ValidateReadPtr(p,cb) \
    {if(IsBadReadPtr((PVOID)p,cb) == TRUE) \
        DbgBreak("Invalid read pointer");}

I suspect that in your project it's defined as 0 for one or both of the following reasons:

  • to make the code that uses it compile even when the wxdebug.h header isn't available (ie., not using the Windows Mobile SDK)
  • IsBadReadPtr() is now considered a dangerous API that shouldn't be used. The docs for IsBadreadPtr() say, "Important This function is obsolete and should not be used. Despite its name, it does not guarantee that the pointer is valid or that the memory pointed to is safe to use. For more information, see Remarks...". And Raymond Chen wrote an article about the problems with IsBadReadPtr(): IsBadXxxPtr should really be called CrashProgramRandomly


It was probably used for something else, and then was redefined as 0.

That's the beauty of macros, you can use them in your code, and then, one simple redefinition is good enough to change all occurrences of that macro in the code.

What's probably happening now is the programmer wants that validation (ValidateReadPtr) always return FALSE (0 in C/C++).


See here: http://msdn.microsoft.com/en-us/library/dd407304(VS.85).aspx


if (!ValidateReadPtr(p,cb))
   printf("Your ReadPtr is valid\n");

;)

0

精彩评论

暂无评论...
验证码 换一张
取 消