The usual way to do this via memcpy, rather than either a union (requires some non-portable extension like &quot;packed&quot;) or pointer casting (invokes undefined behavior if alignment isn&#x27;t satisfied).