This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: strict aliasing: how to swap pointers
- From: "Rupert Wood" <me at rupey dot net>
- To: "'Evan Jones'" <evanj at MIT dot EDU>
- Cc: <gcc-help at gcc dot gnu dot org>
- Date: Wed, 30 Apr 2008 00:37:05 +0100
- Subject: RE: strict aliasing: how to swap pointers
- References: <481785A7.3060506@mit.edu>
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.