Octavian Iosup

MC9S08SH16 - Local static variable initialization

Discussion created by Octavian Iosup on Jan 28, 2010
Latest reply on Jan 30, 2010 by CompilerGuru


I am relatively new to Freescale micros and CodeWarrior. I currently work at a project that uses a MC9S08SH16 micro and I have a question about variable initialization at start-up.

I used the following code


#define DEFINED_VAR  


void nameFunction1(void)


  static unsigned char var1 = DEFINED_VAR;


  if(var1 != 0)






    var1 = DEFINED_VAR;

    nameFunction2(); /* function call */  




} /* end of function */


At compile time  I got the following warning


L1981:  No copydown created for initialized object "var1.4". Initialization data lost. 


Basically at start-up  the var1 was initialized to 0 and the "else" branch was executed immediately even tough that was not the intention.

I realize that are work around solutions for this particular example but I would like to understand why this warning message in showed up the first place and what settings must be enabled in the project such that the static local variable gets initialized at start-up.


Thank you for your consideration