the debug problem in VC++
-
say i have a function int fun(int *a), and other function int fa(); int fb(), int fc(),....int fn(); all the them will call the fun(int *a), but the problem is, when I run the program, the vc++ tells me some of them pass the NULL pointer to the fun(int *a) which make mistake, but could not tell me which function calls the fun(int *a) and then pass the NULL pointer to it, so dear guys, how could I know which one call the fun(int *a) that pass the NULL pointer? Thanks.
-
say i have a function int fun(int *a), and other function int fa(); int fb(), int fc(),....int fn(); all the them will call the fun(int *a), but the problem is, when I run the program, the vc++ tells me some of them pass the NULL pointer to the fun(int *a) which make mistake, but could not tell me which function calls the fun(int *a) and then pass the NULL pointer to it, so dear guys, how could I know which one call the fun(int *a) that pass the NULL pointer? Thanks.
:confused: I didn't really understand your problem. Do you have a crash and would like to find the problem ? If yes, did you use your debugger to track the problem ? Using the callstack you'll be able to find which function passed a NULL pointer.
Cédric Moonen Software developer
Charting control [v1.3] -
say i have a function int fun(int *a), and other function int fa(); int fb(), int fc(),....int fn(); all the them will call the fun(int *a), but the problem is, when I run the program, the vc++ tells me some of them pass the NULL pointer to the fun(int *a) which make mistake, but could not tell me which function calls the fun(int *a) and then pass the NULL pointer to it, so dear guys, how could I know which one call the fun(int *a) that pass the NULL pointer? Thanks.
Hi, If your program stops with runtime error, as Cedric said, use the "call stack" window and see which one of fa(), fb().. fn() is called just before fun(). Or try using only one function from fa(), fb() ... fn() at a time and find out. If you have problem still post the relevant code snippet. Best Regards, Suman
-- "Programming is an art that fights back!"
-
say i have a function int fun(int *a), and other function int fa(); int fb(), int fc(),....int fn(); all the them will call the fun(int *a), but the problem is, when I run the program, the vc++ tells me some of them pass the NULL pointer to the fun(int *a) which make mistake, but could not tell me which function calls the fun(int *a) and then pass the NULL pointer to it, so dear guys, how could I know which one call the fun(int *a) that pass the NULL pointer? Thanks.
Well one way like others said, if you are programming in Visual Studio, you can set break point and check the call stack when program crashes. Another way is to do it like this:
int fa() { int* a; . . . if(a == NULL) { cout << "fa is the culprit"; } fun(a); }
-Saurabh -
say i have a function int fun(int *a), and other function int fa(); int fb(), int fc(),....int fn(); all the them will call the fun(int *a), but the problem is, when I run the program, the vc++ tells me some of them pass the NULL pointer to the fun(int *a) which make mistake, but could not tell me which function calls the fun(int *a) and then pass the NULL pointer to it, so dear guys, how could I know which one call the fun(int *a) that pass the NULL pointer? Thanks.
Use the debugger to set a breakpoint in
fun()
. Whena
equalsNULL
, check the call stack."Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
say i have a function int fun(int *a), and other function int fa(); int fb(), int fc(),....int fn(); all the them will call the fun(int *a), but the problem is, when I run the program, the vc++ tells me some of them pass the NULL pointer to the fun(int *a) which make mistake, but could not tell me which function calls the fun(int *a) and then pass the NULL pointer to it, so dear guys, how could I know which one call the fun(int *a) that pass the NULL pointer? Thanks.
Did you get runtime error?