Click here to Skip to main content
15,905,427 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: DLL Registeration Issue Pin
fadee23-Sep-03 23:36
fadee23-Sep-03 23:36 
GeneralNeed help for STL Pin
zma6423-Sep-03 18:43
zma6423-Sep-03 18:43 
GeneralRe: Need help for STL Pin
Joaquín M López Muñoz23-Sep-03 20:14
Joaquín M López Muñoz23-Sep-03 20:14 
GeneralThanks Pin
Anonymous24-Sep-03 3:30
Anonymous24-Sep-03 3:30 
QuestionDo you write "precondition" and "postcondition" in your comment? Pin
Link260023-Sep-03 18:27
Link260023-Sep-03 18:27 
AnswerRe: Do you write "precondition" and "postcondition" in your comment? Pin
Michael Dunn23-Sep-03 18:46
sitebuilderMichael Dunn23-Sep-03 18:46 
GeneralRe: Do you write "precondition" and "postcondition" in your comment? Pin
Link260023-Sep-03 18:55
Link260023-Sep-03 18:55 
GeneralRe: Do you write "precondition" and "postcondition" in your comment? Pin
David Crow24-Sep-03 2:22
David Crow24-Sep-03 2:22 
VW_Red_Jetta wrote:
Well, what is the formal difinition of "assertion"?

I'll provide you a comment from Steve McConnell:

The main difference between "if" tests and assertions is that assertions should test for conditions that you expect *never* to happen; "if" tests are for conditions that you plan to deal with. Assertions should not take the place of normal error-processing code. They should be used to flush out defects in your code. Put differently, an assertion should never fire unless there is a defect.

When I posed a similar question to Steve Maguire (my function had a signature of Foo( LPSTR )), his response was:

The question you should ask is this:

Is it legal for another programmer to call
Foo() with a null pointer?

or phrased differently:

If a programmer passed NULL to Foo(), would
that be a bug in the calling code?

If you decide that getting NULL is an illegal condition (based on how you designed Foo()) and indicates a bug in the calling function, then you should use ASSERT. If, on the otherhand, Foo()'s design makes getting a NULL pointer reasonable, and would not indicate a bug in the caller, then you should be using the "if".

You may want to use both the ASSERT and "if". You'd use both when getting a NULL would indicate a bug, and when you'd still want the code to behave intelligently even when it gets garbage. The typical scenario would be aircraft controller software, or radiation machine software. Bugs in either of these pieces of software could be deadly and so you'd keep the "if" just in case a bug makes it into the final code. Hopefully the ASSERT would alert you to the bug long before then.

Probably the best way to figure out whether to use an ASSERT or an "if" is to follow this guideline:

Completely finish the function as you intend
to ship it. Once you're convinced that you've
got the code as you plan to ship it, _only then_
do you add assertions (and debug code), _without_
changing what your ship code does.

(Remember, debug code is strictly _extra_ code.)

Using this guideline, you can see that if your ship code has to handle NULL pointers, then you have to use an "if" statement to handle the NULL pointer. If the ship code doesn't have to handle the NULL pointer, then you can ASSERT that getting one is illegal so that it alerts callers to their bugs.



Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?

GeneralRe: Do you write "precondition" and "postcondition" in your comment? Pin
Link260024-Sep-03 12:15
Link260024-Sep-03 12:15 
GeneralRe: Do you write "precondition" and "postcondition" in your comment? Pin
David Crow25-Sep-03 9:44
David Crow25-Sep-03 9:44 
GeneralQuestion about mmap Pin
George223-Sep-03 16:55
George223-Sep-03 16:55 
GeneralHooking keyboard events not working on Win98 Pin
tommyfotak23-Sep-03 16:53
tommyfotak23-Sep-03 16:53 
GeneralPlatform SDK Pin
esepich23-Sep-03 15:58
esepich23-Sep-03 15:58 
GeneralRe: Platform SDK Pin
David Stone23-Sep-03 16:10
sitebuilderDavid Stone23-Sep-03 16:10 
GeneralPointer to Function for Phase Management Pin
wogerdoger23-Sep-03 15:38
wogerdoger23-Sep-03 15:38 
GeneralRe: Pointer to Function for Phase Management Pin
David Crow23-Sep-03 16:32
David Crow23-Sep-03 16:32 
GeneralCheers Pin
wogerdoger23-Sep-03 17:31
wogerdoger23-Sep-03 17:31 
GeneralWarning: The wheels have fallen off the camel Pin
wogerdoger24-Sep-03 9:04
wogerdoger24-Sep-03 9:04 
GeneralFinding hardware Device Infomation... Pin
Member 40481323-Sep-03 15:25
Member 40481323-Sep-03 15:25 
GeneralRe: Finding hardware Device Infomation... Pin
David Crow23-Sep-03 16:34
David Crow23-Sep-03 16:34 
GeneralRe: Finding hardware Device Infomation... Pin
Manikandan23-Sep-03 21:08
Manikandan23-Sep-03 21:08 
GeneralRe: Finding hardware Device Infomation... Pin
David Crow24-Sep-03 2:09
David Crow24-Sep-03 2:09 
GeneralAfter OnInitDialog() Pin
Anonymous23-Sep-03 14:07
Anonymous23-Sep-03 14:07 
GeneralRe: After OnInitDialog() Pin
Anonymous23-Sep-03 15:28
Anonymous23-Sep-03 15:28 
GeneralRe: After OnInitDialog() Pin
David Crow23-Sep-03 16:39
David Crow23-Sep-03 16:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.