|
-
June 20th, 2007, 03:20 AM
#1
[RESOLVED] Assertions
Hi,
Steve Maguire in Writing Solid Code mentions how his re-write of an old library, which previously had no assertions, caused so many assertion errors in the code that now used the new library.
How can adding assertions to my code help discover otherwise unfound bugs? If my code is running fine then it means that I have checked for invalid parameters to functions and other stuff like that. Then how do assertions are supposed to help?
Code:
void foo (HWND hWnd)
{
ASSERT (::IsWindow (hWnd));
//Do something with hWnd
}
Now in release build the ASSERT will be removed, so how can I be so sure that an invalid handle won't be passed any other time?
Won't it be better to do something like this:
Code:
void foo (HWND hWnd)
{
ASSERT (hWnd);
if (!hWnd)
return;
...
}
So what I think is that assertions only notify you of problems and prevents me from stepping into the code. Is this correct? Or I'm missing something?
Thanks.
Last edited by logan; June 20th, 2007 at 03:45 AM.
Reason: typos
"I rather not play football than wear Nerrazzuri shirt" - Paolo Maldini
FORZA MILAN!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|