I am reading The C++ PL by Bjarne Stroustrup. It states about unions that:
"Unions are sometimes misused for ‘‘type conversion.’’ This misuse is practiced mainly by programmers trained in languages that do not have explicit type conversion facilities, so that cheating is necessary. For example, the following ‘‘converts’’ an int to an int∗ simply by assuming bitwise equivalence:
union Fudge {
int i;
int∗ p;
};
int∗ cheat(int i)
{
Fudge a;
a.i = i;
return a.p; // bad use
}
This is not really a conversion at all. On some machines, an int and an int∗ do not occupy the same amount of space, while on others, no integer can have an odd address. Such use of a union is dangerous and nonportable."
Can someone explain in simpler words what the author means here? Why is it not a conversion? If not like this then how do we achieve type-conversion?