Hi,
While assigning from long to short, LSB 2 bytes is 0, where as MSB is filled with values from the func1() Algorithm values from stack. Why is this happening, why the compiler is trying to get these junk values to the MSB 2bytes?
#include <stdio.h>
unsigned short func1(void); // NB: function prototype !
int main(void)
{
unsigned long int L = 0;
unsigned short K = 0;
L = func1();
printf("%lu", L); // prints junk values
K = L;
printf("%u", K); // prints 0
return 0;
}
unsigned short func1(void)
{
unsigned short i = 0;
// Algorithm Logic!!!
return i; // returns 0
}