Search code examples
cpointersunionsc89

Why is it undefined to derefrence a pointer to extern union?


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;                
}

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).