This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

problem in initilise static variable

Hi,

I am using c51 keil compiler with cygnal chip c8051C020.
I find problem in initilise static variable.
exp.
main()
{
static unsigned char i =0 ;
i++;
}
when i write this type of code & simulate it ,i find that i is not initilise to 0.

Note:this is just example code & not the actual program i work.
If any specify me the reasion it will help me lot.

Regards,
Pandurang S.

Parents
  • static unsigned char i =0 ;
    
    Why do you use keyword static in connection with an immediate variable allocation i=0?

    I think this is nonsense. Simply write
    unsigned char i =0 ;
    
    That has the same effect!

    Martin

    BTW: Do you know what static does? A storage class that, when used with a variable declaration in a function,
    causes variables to retain their value after exiting the block or function in
    which they are declared.

Reply
  • static unsigned char i =0 ;
    
    Why do you use keyword static in connection with an immediate variable allocation i=0?

    I think this is nonsense. Simply write
    unsigned char i =0 ;
    
    That has the same effect!

    Martin

    BTW: Do you know what static does? A storage class that, when used with a variable declaration in a function,
    causes variables to retain their value after exiting the block or function in
    which they are declared.

Children