Type punning with unions

TLDR: don&rsquo;t use unions for type punning; always use memcpy . Sometimes you might want to reinterpret a value of one type as value of another type. For example you might have an integer parameter, but you know that it actually contains a float value. Let&rsquo;s assume the integer was large enough to store the float somehow, and now you want to get the value back. If you follow wikipedia you…