cu coredumps

Joerg Sonnenberger joerg at britannica.bec.de
Wed Oct 27 10:25:22 PDT 2004


On Wed, Oct 27, 2004 at 12:51:51PM -0400, Timour Ezeev wrote:
> 	2. If you dont want to create a new pointer, swap pointers in plase,
> 	   like this
> 
> 	(int)tmp_cp ^= (int)cp; (int)cp ^= (int)tmp_cp; (int)tmp_cp ^= 
> 	(int)cp;
> 	free(tmp_cp);
> 
> 	or something similar :)

No, please don't. This is
(a) obscure and hard to read
(b) uses a depricated extension of GCC (lhs cast)
(c) depends on sizeof(int) == sizeof(void *)
(d) slower than the version with a local variable

If you don't want to add a variable for the whole function scope, do a
	{
		void *local_tmp = cp;
		cp = tmp_cp;
		tmp= cp;
	}
which is both easier to read and faster.

Joerg





More information about the Bugs mailing list