Hi all,
I have a problem when trying to return a union type variable from function. The union is defined in a header file called "Dummy.h" like that:
Code:
typedef union
{
uint32_t A;
uint32_t B;
} dummy_union;
In "Dummy.c", I declared a function called dummy_union() which just saves 0x55 and 0xFF to a "dummy_union" variable "X" and returns it.
Code:
#include "Dummy.h"
inline dummy_union Dummy_Task(void)
{
dummy_union X;
X.A = 0x55;
X.B = 0xFF;
return X;
}
Furthermore, Dummy_caller() calls Dummy_Task() and stores its return to a new "dummy_union" variable "var1". Finally, the 2 members of "var1" are printed.
Code:
void Dummy_caller(void)
{
static dummy_union var1;
var1=Dummy_Task();
printf("member 1 of var1 is %u \n", var1.A);
printf("member 2 of var1 is %u \n", var1.B);
}
However, both printfs give 0xFF. Does anyone have any idea why?
Thanks!