Hi,
I am learning about unions. I have the following code declaring a union of 2 structures, and pointers to the structures. How can I assign a pointer of the structure to the structure in the union ?
typedef struct {
char A[100]
} Struct1;
typedef struct {
char B[100]
} Struct2;
typedef union {
Struct1 s1;
Struct2 s2;
} MyUnion;
struct Struct1 * sp1;
struct Struct2 * sp2;
MyUnion union1;
main()
{...
/* Is this correct ?? */
union1.s1=*sp1;
...
}
I am getting "dereferencing pointer to incomplete type" compile errors with the above assignment.
I am learning about unions. I have the following code declaring a union of 2 structures, and pointers to the structures. How can I assign a pointer of the structure to the structure in the union ?
typedef struct {
char A[100]
} Struct1;
typedef struct {
char B[100]
} Struct2;
typedef union {
Struct1 s1;
Struct2 s2;
} MyUnion;
struct Struct1 * sp1;
struct Struct2 * sp2;
MyUnion union1;
main()
{...
/* Is this correct ?? */
union1.s1=*sp1;
...
}
I am getting "dereferencing pointer to incomplete type" compile errors with the above assignment.