C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

pointer or what?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
joel
Guest





PostPosted: Wed Mar 09, 2005 11:00 am    Post subject: pointer or what? Reply with 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).

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





PostPosted: Wed Mar 09, 2005 11:41 pm    Post subject: Re: pointer or what? Reply with quote



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





PostPosted: Wed Mar 09, 2005 11:41 pm    Post subject: Re: pointer or what? Reply with quote



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





PostPosted: Thu Mar 10, 2005 8:33 pm    Post subject: Re: pointer or what? Reply with quote

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





PostPosted: Mon Apr 18, 2005 3:10 pm    Post subject: Re: pointer or what? Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.