Monday, December 2, 2013

Uninitialized variable problem

GCC Provides some pretty good warning features for you, to help avoid common problems.
One of this is warning for uninitialzed variables.

Let's see the following code:

 typedef union  
 {  
   uint8_t value1;  
   uint8_t value2;  
 } demostruct;  
 .  
 .  
 .  
 demostruct uninited;  
 int i;  
 for (i = 0; i < uninited.value1; i++)  
 {  
      //do something  
 }  

You'll probably be in some serious trouble running this code, as whatever you do in the for loop, the execution of it surely won't be as you imagined.