Assuming we dereference correctly and use the integer right, is this a good programming practice?
union {
int x;
struct node * next;
};
Assuming we dereference correctly and use the integer right, is this a good programming practice?
union {
int x;
struct node * next;
};
Unions are rather low-level language feature. There are no meaningful reason for any restrictive "good programming practices" to exist with regards to which types can reside together in a union. The purpose of union is to "multiplex" memory usage: to save space by storing several unrelated objects with non-overlapping lifetimes in the same memory region.
If that's what you need - go for it.
Unions are sometimes used for raw memory reinterpretation (AKA type-punning). This usage of unions used to be illegal, until it was formally legalized in one of the late technical corrigendums to C99 standard. While it has its uses, type-punning can indeed be seen as questionable programming practice.