?
Solved

help debugging

Posted on 2003-03-10
8
Medium Priority
?
607 Views
Last Modified: 2008-03-10
I have been asked to debug a piece of code. I am having a problem understanding part of it. Here is the code:

if ( update & No_UpdateType == No_UpdateType )
     
     {    
          return false;
         
     }  
     
if ( update & Private_UpdateType == Private_UpdateType )
         
     {    
          for ( i = 0; i < m_numEvents; ++i )      
          {        
               if ( m_eventFilter[i] == key )
                   
               {          
                    retval = true;  
               }
     
               else
               {        
                    retval = false;        
               }      
     }
         
          if ( retval )      
          {
               SendPrivateNetworkEvent( buffer, key, val );  
          }  
     }  



What I don't understand are the conditions in the two main if statements:

if ( update & No_UpdateType == No_UpdateType )
and
if ( update & Private_UpdateType == Private_UpdateType )

Should there be two ampersands? Is update a class? I don't know. In case that isn't enough enough information, below is the entire code segment. I would appreciate any help.

boolEntity::SetInt( INT_STAT key, int val, UpdateType update )
{  
  m_Qualities->SetInt( key, val );  //I am also a litle confused with this line
  int i;  
  bool retval;
  byte* buffer = new byte[ 256 ];

  if ( update & No_UpdateType == No_UpdateType )
    {    return false;  }  

  if ( update & Private_UpdateType == Private_UpdateType )
  {  
    for ( i = 0; i < m_numEvents; ++i )      
    {    
      if ( m_eventFilter[i] == key )
         {retval = true; }
      else
         {retval = false;}      
    }    

    if ( retval )
    {
      SendPrivateNetworkEvent( buffer, key, val );    
     }  
   }  

  if ( update & Public_UpdateType == Public_UpdateType )
  {      
    for ( i = 0; i < m_numEvents; ++i )
    {
        if ( m_eventFilter[i] == key )
          { retval = true; }
        else
          { retval = false; }      
     }    
   
    if ( retval )
    {    
       SendPublicNetworkEvent( buffer, key, val );  
    }  
  }
  delete buffer;  
  return retval;
}
0
Comment
Question by:sgugi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 8104602

>>What I don't understand are the conditions in the two main if statements:

>>if ( update & No_UpdateType == No_UpdateType )

"update & No_UpdateType" checks whether a certain bit is set in the variable "update" ('&' is the bitwise AND operator). Actually, both statements are redundant,

if ( update & No_UpdateType )

would be enough.

0
 

Author Comment

by:sgugi
ID: 8104977
Thank you jkr, that helped.

Looking at the code again, I realized I had another couple of questions:

What exactly is the point of the buffer in this code segment?
and
What is the purpose of this line?
m_Qualities->SetInt( key, val )  
0
 
LVL 86

Accepted Solution

by:
jkr earned 225 total points
ID: 8105036
>>What exactly is the point of the buffer in this code segment?

To be hinest - none. It is never being initialized, and unless it is some sort of of a receive buffer (which its usage with 'SendPublicNetworkEvent()' does not suggest), it seems to be bogus.

>>m_Qualities->SetInt( key, val )  

It calls a method of an object via a pointer to that object.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:sgugi
ID: 8105432
Thanks again jkr. Do you suggest getting rid of the buffer entirely?
0
 
LVL 86

Expert Comment

by:jkr
ID: 8105492
>>Do you suggest getting rid of the buffer entirely?

Only if 'SendPublicNetworkEvent()' can cope with a NULL pointer as the 1st argument.
0
 
LVL 86

Expert Comment

by:jkr
ID: 8138303
Anything else you need to know?
0
 

Author Comment

by:sgugi
ID: 8143289
I think I'm all set now. Thanks for your help!
0
 
LVL 86

Expert Comment

by:jkr
ID: 8143546
So, could we close this Q then? .o)
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question