CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

A strange problem...

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ye



Joined: 11 May 2005
Posts: 57
Location: london

View user's profile Send private message

A strange problem...
PostPosted: Fri Oct 21, 2005 5:53 am     Reply with quote

Hi, all,

I post this strange thing here and hope ppl help

Code:


void StopConditionExamination( void )
{

   int count_loop;
   const char bottom[22]=" CANCEL         NEXT ";
   
   /*
   fprintf(COM_B,"\n*****I am here 1******\n");
   fprintf(COM_B,"\nTEtest_done = %d\n",TEtest_done);
   fprintf(COM_B,"\nTEtest_checkfit = %d\n",TEtest_checkfit);
   fprintf(COM_B,"\nmode = %d\n",mode);
   */
   
   ///////////////////////////////////////////////////////////////
   //////////////      Successful Test Done!     /////////////////   
   ///////////////////////////////////////////////////////////////
   if( (lastresult == IPCOMMS_LASTRESULT_VALIDRESULT) && (last_mode == MODE_TEDATACOLLECT) )
   {
      TEtest_timeout = 0;
      TEtest_done = 1;
      TEtest_stop = 0;
      TEtest_cancel = 0;
      TEtest_checkfit = 0;

      fprintf(COM_B,"\n*****I am here 2******\n");
      fprintf(COM_B,"\nTEtest_done = %d\n",TEtest_done);
      fprintf(COM_B,"\nTEtest_checkfit = %d\n",TEtest_checkfit);
      fprintf(COM_B,"\nmode = %d\n",mode);

   }
   
   ///////////////////////////////////////////////////////////////
   //////////     Stimulus level falls out of range     //////////
   ///////////////////////////////////////////////////////////////
   else if( (((targetstimoklevel - targetstimokrange) > stimdb) || ((targetstimoklevel + targetstimokrange) < stimdb)) 
&& (mode == MODE_TEDATACOLLECT) )
   {      

       /*
      fprintf(COM_B,"\n*****I am here 3******\n");
      fprintf(COM_B,"\nTEtest_done = %d\n",TEtest_done);
      fprintf(COM_B,"\nTEtest_checkfit = %d\n",TEtest_checkfit);
      fprintf(COM_B,"\nmode = %d\n",mode);
      */

      TEtest_timeout = 0;
      TEtest_done = 0;
      TEtest_stop = 0;
      TEtest_cancel = 0;
      TEtest_checkfit = 1;
      
   }

   fprintf(COM_B,"\n*****I am here 4******\n");
   fprintf(COM_B,"\nTEtest_done = %d\n",TEtest_done);
   fprintf(COM_B,"\nTEtest_checkfit = %d\n",TEtest_checkfit);
   fprintf(COM_B,"\nmode = %d\n",mode);

    ....................................................
    ....................................................
}



The code above is basically a single function. I hide other part of the function and only 2 IF statements are given here. You can see there are groups of FPRINTFs around. They are for testing purpose and do not impose any significance to the actual operation of the code.

Fundamentally, you can see conditions of the 2 IF statements are irrelevant and the variables in the conditions are all global variables.

The weird thing is here:
When this function is called, conditions for the 1st IF are met and those for the 2nd one are not met at all. So supposedly, the result should be:

TEtest_done =1;
TEtest_checkfit = 0;

However the result I got from Hyperterminal is:

TEtest_done =1;
TEtest_checkfit = 1;

The strange thing here is:
Since the 1st IF works and the 2nd one doesn't, TEtest_checkfit shouldn't be 1 !! It apears like the 2nd IF works when conditons are not met at all! Even if the 2nd IF works, it is impossible for both variables to be 1. But I can say the second IF didn' work by looking at the hyperterminal.

The even more strange thing is:
The problem can only solved by putting the second group of FRINTFs, i.e., the group begins with 'I am here 2'. As long as they are there, the problem is gone and TEtest_checkfit becomes 0; as soon as I comment them out, problem happens!


People, please help! I am so puzzled!
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Fri Oct 21, 2005 7:25 am     Reply with quote

Take out the else statement and replace it for another single if.
I canīt see any correspondence in the variables involved inside the two if statements
for being using else statement. Donīt see why should be exclusive.

Would be like this:

Code:


  if( (lastresult == IPCOMMS_LASTRESULT_VALIDRESULT) && (last_mode == MODE_TEDATACOLLECT) )
   {
    .......
    ....... 
   }
   
  if( (((targetstimoklevel - targetstimokrange) > stimdb) || ((targetstimoklevel + targetstimokrange) < stimdb)) 
&& (mode == MODE_TEDATACOLLECT) )
   {       
    .......
    .......
   }



Humberto
ye



Joined: 11 May 2005
Posts: 57
Location: london

View user's profile Send private message

PostPosted: Fri Oct 21, 2005 8:01 am     Reply with quote

I can't take awy the else here.

Before continue, I am wondering whether a loop like
if()
else if()
else if()
can only alow only IF to be executed like SWITCH CASE does?

If the answer is yes, i must keep the ELSE because though the conditons in the IF statements are totally irrelevant, at a time the code only alow one event to happen. If more than one event happens simultaneously, i,e,, two IFs are met, the operation of the code will be messed up.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Fri Oct 21, 2005 8:15 am     Reply with quote

Quote:

If more than one event happens simultaneously, i,e,, two IFs are met, the operation of the code will be messed up.


The code posted didnīt give us enough visibility to know what your intention is, but if the quoted phrase is true, you must use a switch() and NOT the else statement.

Humberto
ye



Joined: 11 May 2005
Posts: 57
Location: london

View user's profile Send private message

PostPosted: Fri Oct 21, 2005 9:04 am     Reply with quote

thanks humberto,

...................................

Let's forget about IF or SWITCH here and go back to the problem.

Obviously the conditons for the second IF are not met and there is no way for TEtest_checkfit to be 1! And I don't think it has anything to do with the IFs

I am suspecting memory collision but really not sure.

Still nobady can answer what's going wrong here?
ye



Joined: 11 May 2005
Posts: 57
Location: london

View user's profile Send private message

PostPosted: Fri Oct 21, 2005 9:05 am     Reply with quote

thanks humberto,

...................................

Let's forget about IF or SWITCH here and go back to the problem.

Obviously the conditons for the second IF are not met and there is no way for TEtest_checkfit to be 1! And I don't think it has anything to do with the IFs

I am suspecting memory collision but really not sure.

Still nobady can answer what's going wrong here?
ye



Joined: 11 May 2005
Posts: 57
Location: london

View user's profile Send private message

PostPosted: Fri Oct 21, 2005 9:06 am     Reply with quote

thanks humberto,

...................................

Let's forget about IF or SWITCH here and go back to the problem.

Obviously the conditons for the second IF are not met and there is no way for TEtest_checkfit to be 1! And I don't think it has anything to do with the IFs

I am suspecting memory collision but really not sure.

Still nobady can answer what's going wrong here?
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Fri Oct 21, 2005 3:03 pm     Reply with quote

Quote:

I am suspecting memory collision but really not sure


We doesnīt know how are you are testing this code nor the tools you are using
nor the whole enviroment, but if this is your conclusion, Shocked I give up here.


Humberto
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
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, 2005 phpBB Group