This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: strict aliasing: how to swap pointers


Evan Jones wrote:

> I have a function to swap any two pointers (assuming that
> sizeof(void*) == sizeof(T*)). I would like to use it without
> violating strict aliasing rules.

I don't know how to fight aliasing rules but as another approach you could template the function instead, i.e.

     template<typename T> T* exchange(T** ptr, T* next);

     exchange<int>(&a, &v2);

since you're using C++ here.

Rup.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]