Click here to Skip to main content
15,890,282 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# versus C++, null references and protecting against them Pin
Paul Michalik15-Jan-11 2:23
Paul Michalik15-Jan-11 2:23 
AnswerRe: C# versus C++, null references and protecting against them Pin
PIEBALDconsult15-Jan-11 4:12
mvePIEBALDconsult15-Jan-11 4:12 
GeneralRe: C# versus C++, null references and protecting against them Pin
bob1697215-Jan-11 5:00
bob1697215-Jan-11 5:00 
AnswerRe: C# versus C++, null references and protecting against them Pin
Chuck O'Toole15-Jan-11 17:14
Chuck O'Toole15-Jan-11 17:14 
GeneralRe: C# versus C++, null references and protecting against them Pin
bob1697215-Jan-11 19:23
bob1697215-Jan-11 19:23 
GeneralRe: C# versus C++, null references and protecting against them Pin
Chuck O'Toole15-Jan-11 20:56
Chuck O'Toole15-Jan-11 20:56 
GeneralRe: C# versus C++, null references and protecting against them Pin
bob1697216-Jan-11 5:24
bob1697216-Jan-11 5:24 
GeneralRe: C# versus C++, null references and protecting against them Pin
Chuck O'Toole16-Jan-11 6:00
Chuck O'Toole16-Jan-11 6:00 
I'm afraid you missed a subtle point in my example, the point that gets you into your function with a NULL value. I've simplified it below

void Bar(CObArray &ar)
{
	int foo = ar.GetCount();
}

void Foo(void)
{
	CObArray *bob = NULL;

	Bar(*bob);
}
set a breakpoint on the "int foo = ar.GetCount()" and observe that ar cannot be examined in the debugger, it's value is null. Note that you do in fact get to that statement, that is, the "Bar(*bob)" in the function "Foo" does not throw an exception. Although it looks like it is dereferencing the clearly null pointer, it's really just creating the argument for Bar by getting the address of the CObject and passing it, that is, making a "by reference" value for the Bar function. Therefore, the "crash" happens in "Bar" (i.e. your function) rather than at the invocation site.

In my first reply, I was showing that the "ToBeAdded" object, which was valid, had a "Members" data member that was, in fact, NULL and that there was no "help" from the compiler / language rules that prevented it from passing NULL, even though the rules appear to say that's illegal.

So, my conclusion was that if you don't want to allow NULL as an input to your functions and that you used to explicitly ASSERT / check for that case, you need to continue to check for that case because simply using "&" to eliminate that possibility was not going to work.

Thus ends my rebuttal Smile | :)
GeneralRe: C# versus C++, null references and protecting against them Pin
Paul Michalik16-Jan-11 7:39
Paul Michalik16-Jan-11 7:39 
GeneralRe: C# versus C++, null references and protecting against them Pin
Chuck O'Toole16-Jan-11 7:57
Chuck O'Toole16-Jan-11 7:57 
GeneralRe: C# versus C++, null references and protecting against them Pin
Chuck O'Toole16-Jan-11 8:30
Chuck O'Toole16-Jan-11 8:30 
GeneralRe: C# versus C++, null references and protecting against them Pin
bob1697216-Jan-11 12:29
bob1697216-Jan-11 12:29 
GeneralRe: C# versus C++, null references and protecting against them Pin
Paul Michalik16-Jan-11 20:35
Paul Michalik16-Jan-11 20:35 
GeneralRe: C# versus C++, null references and protecting against them Pin
Paul Michalik15-Jan-11 23:04
Paul Michalik15-Jan-11 23:04 
GeneralRe: C# versus C++, null references and protecting against them Pin
bob1697216-Jan-11 4:57
bob1697216-Jan-11 4:57 
QuestionCOM error [modified] Pin
polycom12314-Jan-11 8:05
polycom12314-Jan-11 8:05 
QuestionDynamic assembly information Pin
Helfdane14-Jan-11 2:32
Helfdane14-Jan-11 2:32 
AnswerRe: Dynamic assembly information Pin
Ravi Sant14-Jan-11 3:49
Ravi Sant14-Jan-11 3:49 
GeneralRe: Dynamic assembly information Pin
Helfdane16-Jan-11 21:05
Helfdane16-Jan-11 21:05 
AnswerRe: Dynamic assembly information Pin
PIEBALDconsult15-Jan-11 9:08
mvePIEBALDconsult15-Jan-11 9:08 
GeneralRe: Dynamic assembly information Pin
Tony Richards16-Jan-11 8:54
Tony Richards16-Jan-11 8:54 
GeneralRe: Dynamic assembly information Pin
PIEBALDconsult16-Jan-11 14:49
mvePIEBALDconsult16-Jan-11 14:49 
QuestionRunning an exe file ( I mean a program) from inside my own program Pin
Fred 3414-Jan-11 1:41
Fred 3414-Jan-11 1:41 
AnswerRe: Running an exe file ( I mean a program) from inside my own program Pin
PIEBALDconsult14-Jan-11 1:46
mvePIEBALDconsult14-Jan-11 1:46 
AnswerRe: Running an exe file ( I mean a program) from inside my own program PinPopular
Luc Pattyn14-Jan-11 1:48
sitebuilderLuc Pattyn14-Jan-11 1:48 

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.