3 ms·
the opt-out in C is to use char*, which is specifically allowed to alias other types. There are also GCC extensions to build other types that may alias.
by mgaunard 1y ago
the opt-out in C is to use char*, which is specifically allowed to alias other types.
There are also GCC extensions to build other types that may alias.
- ralfj 1y agoThat doesn't let you treat data in-place at two different types, unless one of them happens to be char. So you still need to make a copy in many cases, e.g. to convert between an array of uint32_t and an array of uint16_t. In some cases you can use unions, but that, too, is very limited, and I am not sure it would let you do this particular case.
- mgaunard 1y agoNot if you use may alias. Also yes, that's the point of the C++ object model, only one type may exist in one location at a time. Since usually different register banks are used for different types, having to copy makes sense.