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 CCS Technical Support

How many stack locations are used in this loop structure ?

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



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

How many stack locations are used in this loop structure ?
PostPosted: Mon Oct 23, 2006 10:30 pm     Reply with quote

Hi,

I have the following code...

Code:



void save()
{


 //a do while loop is implemented here

}

int16 func7(int h)
{

 //a for loop is implemented here

 
}


void proc4(int nGroup,int nSelStep,int DevCode)
{

  int j;
 
  j=func7();



}

void proc5()
{
 int g;

 //a do while loop is implemented here

}

int func2()
{
  proc5();

}


int16 func1()
{
  int v,m;

  v=func2();
  v=func2();
  m=func2();
  m=func2();

   return(make16(v,m));

}

void main()
{

   do
   {

     if (bTransferFrom==1)
     { 
        bTransferFrom=0;
        for (n=0;n<2;n++)
        {
           T1=func1();
           proc4(1,4,3);
        }

   }while(TRUE);

}




The above code shows the only the structure of the loops.

The code compiles well, and the LST file shows a stack usage of 7. Althogh the mcu works well sometimes for some reason it misses some operations , is it possible that the nested loop structure causes it to do so ??

thanks
arunb
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 23, 2006 11:37 pm     Reply with quote

Quote:

The LST file shows a stack usage of 7. Although the mcu works
well sometimes for some reason it misses some operations.

Look for code that writes beyond the end of an array.
For example, suppose you have a string that is 16 characters long.
If you create an array as in the following code, the string will over-write
the 'i' variable when you copy a string to the array.

That's because a string has a 0x00 byte at the end. It's really 17 bytes
long -- 16 characters, plus the 0x00 at the end.
Code:

void main()
{
char array[16];
int8 i;

}

If the 'i' variable is being used to count iterations in a for() loop,
the code could behave in an erratic manner, and it could appear
to "miss some operations".
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