| View previous topic :: View next topic |
| Author |
Message |
joel Guest
|
Posted: Wed Mar 09, 2005 11:00 am Post subject: pointer or what? |
|
|
Hello Group,
Please consider below code and answer my question. This code is placed
in a function and the function is called several time inside a loop.
It works for three times and for the forth time it gets stuck for some
reason which I'm sure it must be pointer.
Assert doesn't complain but line # 2 doesn't happnen to show (as I said
except for times 1,2,3).
Any suggestions?
{
...
1 assert(m_pPointer != NULL);
2 if (m_pPointer)
3 printf("npointer is OK");
4 else
5 printf("npointer is bad");
6
7
8 //This means m_pTiff is TRUE and of course it returns TRUE
9 return (m_pPointer != NULL);
}
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
DavidAFerguson@hotmail.co Guest
|
Posted: Wed Mar 09, 2005 11:41 pm Post subject: Re: pointer or what? |
|
|
| Quote: | 2 if (m_pPointer)
3 printf("npointer is OK");
4 else
5 printf("npointer is bad");
|
Perhaps the output is not being flushed (maybe it is an output
buffer). You could try flushing the output. On some systems
adding a 'n' to the end of string will cause it to automatically
be flushed.
printf("npointer is OKn")
^^ add this
David A. Ferguson <www.davidaferguson.com>
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
simont Guest
|
Posted: Wed Mar 09, 2005 11:41 pm Post subject: Re: pointer or what? |
|
|
If you won't post complete, minimal code exhibiting the problem, the
best I can really suggest is that you break into the program with a
debugger when it gets stuck, and see where it is.
Based on your other post, though ... I'd just like to check that you're
not basing your deduction that the program is stuck solely on the fact
that the printf() hasn't been flushed ...
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ashy Guest
|
Posted: Thu Mar 10, 2005 8:33 pm Post subject: Re: pointer or what? |
|
|
Dear Joel,
The call of assert() should ensure whether your pointer is a valid
one.However the problem,I can find is with the printf().
Try flushing out the buffer,maybe it should work fine after that.
Ashy
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Phillip Jordan Guest
|
Posted: Mon Apr 18, 2005 3:10 pm Post subject: Re: pointer or what? |
|
|
joel wrote:
| Quote: | Hello Group,
Please consider below code and answer my question. This code is placed
in a function and the function is called several time inside a loop.
It works for three times and for the forth time it gets stuck for some
reason which I'm sure it must be pointer.
Assert doesn't complain but line # 2 doesn't happnen to show (as I said
except for times 1,2,3).
|
What exactly do you mean by "gets stuck"?
Also, you haven't given us anywhere near enough code to allow us to help
you. The problem almost certainly lies outside the posted code snippet.
How are you calling this code? How is the variable set? What behaviour
are you expecting? etc.
Since you seem to be implying that you're running into a sort of
"Heisenbug", you're quite likely unintentionally overwriting a memory
location.
Vague questions will only get you vague answers - if you're lucky.
~phil
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|