Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!iuvax!cica!tut.cis.ohio-state.edu!cs.utexas.edu!usc!snorkelwacker!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: Generic Swap Keywords: swap Message-ID: <16864@haddock.ima.isc.com> Date: 13 Jun 90 02:07:41 GMT References: <1990Jun11.133729.6575@cs.utk.edu> <16846@haddock.ima.isc.com> <1990Jun11.214844.21531@agate.berkeley.edu> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Distribution: usa Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 17 In article <1990Jun11.214844.21531@agate.berkeley.edu> dankg@sandstorm.Berkeley.EDU (Dan KoGai) writes: >void *temp; >#define swap(type, x, y) temp = (type *)malloc(sizeof(type));\ > *(type)temp = x; x = y ; y = *(type)temp; free(temp) Those casts don't make sense. I think you want #define swap(type, x, y) temp = malloc(sizeof(type));\ *(type *)temp = x; x = y ; y = *(type *)temp; free(temp) > Since this is a macro, it should work even though your compiler >does not allow passing structs as arguments (struct assignment is valid >since K&R while struct as argument is not). Wrong. The three forms of struct copy (assignment, pass by value, return by value) were all added at the same time, shortly after K&R 1 was published. Karl W. Z. Heuer (karl@ima.ima.isc.com or harvard!ima!karl), The Walking Lint