Question

I have the following code. Why its undefined to derefrence union pointers in the following way ?

extern union MyUn *P1;          
extern union MyUn *P2;

extern void myfunc(void)
{
      *P1 = *P2;                
}
Was it helpful?

Solution

That has nothing to do with unions in particular, and it's not "undefined", either: It's simply a compiler error if you try to dereference a pointer to an incomplete type (for obvious reasons).

OTHER TIPS

If you haven't also defined the union in this source file, the compiler doesn't know how much to copy.

What is the size of the union?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top