Fabulous Adventures In Coding

Eric Lippert's Blog

assert.h

#ifndef ASSERT_H // {
#define ASSERT_H
extern BOOL Debugger();
extern BOOL AssertProc(const char *pszFile, long lwLine, const char *pszMsg);
extern BOOL IsValidReadString(const WCHAR * psz);
extern BOOL IsValidReadStringN(const WCHAR * psz);
extern BOOL IsGoodReadPtr(void * pv, ULONG cb);
extern BOOL IsGoodWritePtr(void * pv, ULONG cb);

#if DEBUG // {
#define AssertMsg(exp, msg) ((exp) || !AssertProc(__FILE__, __LINE__, (msg)) || Debugger())
#else // } DEBUG {
#define AssertMsg(exp, msg)
#endif // DEBUG }

#define Bug(msg)               AssertMsg(FALSE, msg)
#define Assert(exp)            AssertMsg(exp, #exp)
#define AssertReadStringN(exp) AssertMsg(IsValidReadStringN((exp)), "bad string")
#define AssertReadString(exp)  AssertMsg(IsValidReadString((exp)), "bad string")
#define AssertOutPtr(exp)      AssertMsg(IsGoodWritePtr((exp), sizeof(void*)), "bad out pointer")
#define AssertReadPtr(exp)     AssertMsg(IsGoodReadPtr((exp), sizeof(void*)), "bad pointer")

#endif // ASSERT_H }

Published Wednesday, March 31, 2004 6:15 PM by Eric Lippert
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required
Submit

About Eric Lippert

Eric Lippert is a senior developer on the Microsoft C# compiler team. Before that he worked on the framework of Visual Studio Tools For Office. Before that, he worked on the compilers, runtimes and tools for VBScript, JScript, Windows Script Host and other Microsoft Scripting technologies. He lives in Seattle and spends his free time editing books about programming languages, playing the piano, and trying to keep his tiny sailboat upright in Puget Sound.

This Blog

Syndication


© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker