|
I think I understand your problem;
You will definately have to log the variable value every time it changes - AFAIK there is no way of doing this 'automatically'.
The easiest way to log is probably to write the variable value into the stdout stream:
int main(void){
int myVariable = 0;
cout<<"myVariable has the value "<<myVariable;
myVariable = 345;
cout<<"myVariable has the value "<<myVariable;
return 0;
}
However, if you want to log the value outside of the IDE and are not developing a console app, you would need to write it to a file[^].
cheers,
Marco
|
|
|
|
|
Traditional "inline" logging always comes handy, but I was wondering maybe there could be a way to do it more precisely and automatically. Since there are many statements changing the value of the variable, this won't be a practical solution.
Thank you
|
|
|
|
|
ErfanNoury wrote: Since there are many statements changing the value of the variable, this won't be a practical solution.
I thought that you were thinking about something like that - The most important precondition is that you know when a variable value changes.
It is impossible to find this out when the variable of type char, int or any other native type.
The easiest way would probably be to encapsulate the variable with a setter where you can reckon that the value has changed:
int main(void){
int myVariable;
SetMyVariable(myVariable, 0);
SetMyVariable(myVariable, 345);
return 0;
}
void SetMyVariable(int variable, value){
variable = value;
cout<<"myVariable has the value "<< value;
return;
}
|
|
|
|
|
Yeah it's a good idea! I think it is better to wrap the variable into a class and through operator overloading I can log the value of the variable whenever it changes.
|
|
|
|
|
Yes, that's fine. Probably you want to do that just in the debug build.
Veni, vidi, vici.
|
|
|
|
|
According to MSDN, timeSetEvent() run in its own thread, then call timeSetEvent(), when the callback of the timeSetEvent be invoked is undetermined, not like system.threading.timer(), it has a due time to start. right?
|
|
|
|
|
econy wrote: ...the callback of the timeSetEvent be invoked is undetermined... The callback function is called once upon expiration of a single event, or periodically upon expiration of periodic events. That sounds deterministic to me.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
I mean, when is it start to count in a new thread?
OS decide which thread to start, right?
|
|
|
|
|
econy wrote: I mean, when is it start to count in a new thread? When timeSetEvent() returns, I presume.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Hi I am new in c++. Recently I am converting a C++ project to Visual Studio 10 c++ . I am getting an error.
error C2664:
The code is:
XNodes::iterator _tagXMLNode::GetChildIterator( LPXNode node )
{
XNodes::iterator it = childs.begin();
for( ; it != childs.end() ; ++(it) )
{
if( *it == node )
return it;
}
return NULL;
}
How to fix it?
Thanks in advance,
Sai
|
|
|
|
|
Change from
Quote: return NULL; //error is in here
to
return it;
Veni, vidi, vici.
|
|
|
|
|
Hi,
Thanks.
But the logic of the code is if the node matches wuth it then return it else return nothing.
Thanks,
Saimanti
|
|
|
|
|
The 'return it ' I suggested returns childs.end() that is the past-the-end iterator (a 'typed' NULL , roughly speaking).
Veni, vidi, vici.
|
|
|
|
|
Thank you. It worked. But now it is giving another error..
error C2451: conditional expression of type 'std::_Vector_iterator<_Myvec>' is illegal
The code below:
bool _tagXMLNode::RemoveChild( LPXNode node )
{
XNodes::iterator it = GetChildIterator( node );
if( it )
{
delete *it;
childs.erase( it );
return true;
}
return false;
}
Thank in advance,
Saimanti
|
|
|
|
|
I did..
bool _tagXMLNode::RemoveChild( LPXNode node )
{
XNodes::iterator it = GetChildIterator( node );
if( it != childs.end())
{
delete *it;
childs.erase( it );
return true;
}
return false;
}
Is this right?
Thanks,
Saimanti
|
|
|
|
|
It should be correct.
Veni, vidi, vici.
|
|
|
|
|
Thank you very much...
Saimanti
|
|
|
|
|
bool _tagXMLNode::RemoveChild( LPXNode node )
{
XNodes::iterator it = GetChildIterator( node );
if( it != childs.end() ) {
delete *it;
childs.erase( it );
return true;
}
return false;
}
|
|
|
|
|
is this funtion create an event in a asynchronized way? i.e use a background thread?
if I use a timeSetEvent() in a call back function:
void CALLBACK TimerProc1( UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2 ) {
read bus data;
if (data == true) then
timeSetEvent( 5, 1, TimerProc3, 0, TIME_ONESHOT ) ;
}
No timeKillEvent(), then is that means the code will create many events in many threads, right? that is , no release resource.
|
|
|
|
|
if I use same parameters in a timeSetEvent(), then call timeSetEvent() twice, is that mean I created 2 different events?
or Sencond call reset the timer?
|
|
|
|
|
I have an application, there are 2 loops, one is message loop, one is a timeSetEvent() loop.
There is a global variable in both loops.
Now I meet a problem about redraw the screen. The situation like:
wndProc (UINT message, WPARAM wParam, LPARAM lPara)
{
if (GetTickCount() - GVarTck > 4000) then
redraw screen;
switch (message) { handle message;}
}
///////////////////////
OnPaint() {
if (g_timeEvent == 0)
timeSetEvent(50, 5, RefreshScreen,0, TIME_ONESHOT)
}
void CALLBACK RefreshScreen()
{
do Refresh thing;
GVarTikc = GetTickCount();
timeSetEvent(50, 5, RefreshScreen,0, TIME_ONESHOT)
//With GetTickCount() meassured, the time of refreshScreen() is
// about 20 ms.
}
|
|
|
|
|
Why do you need to use a timer to decide when to redraw the screen? You should do it in response to a WM_PAINT message, and you can force a repaint by calling the InvalidateRect() function.
Use the best guess
|
|
|
|
|
Hi, I wonder how much is the cycle of message loop.
I looked through some articles in MSDN, but no articles gave an explain about how much time one cycle message loop needs.
Is the message loop depends on hardware, or OS decide it? and if I have a timer event in my program, then is the message loop has higher priority?
|
|
|
|
|
econy wrote: Is the message loop depends on hardware, or OS decide it? Both I'd immagine. Seems like the answer would be non-deterministic, I'm no expert but Windows being a non real-time OS could and will preempt your program and your message pump for some undetermined time.
Maybe you could get some info using this[^]
econy wrote: timer event in my program, then is the message loop has higher priority?
Not normally see here.[^]
|
|
|
|
|
econy wrote: Hi, I wonder how much is the cycle of message loop.
Approximately 100 messages per second.
|
|
|
|