Xref: utzoo comp.lang.c:29540 comp.std.c:3229 comp.lang.misc:5050 Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uflorida!stat!sun13!prism!gg10 From: gg10@prism.gatech.EDU (Gregory L. Galloway) Newsgroups: comp.lang.c,comp.std.c,comp.lang.misc Subject: Re: Generic swap - comments and questions Summary: don't waste your time Message-ID: <10388@hydra.gatech.EDU> Date: 12 Jun 90 16:34:37 GMT References: <1990Jun12.120637.19933@cs.utk.edu> Followup-To: comp.lang.c Organization: Georgia Institute of Technology Lines: 24 In article <1990Jun12.120637.19933@cs.utk.edu>, wozniak@utkux1.utk.edu (Bryon Lape) writes: > > Thanks for the help in writing the generic swap routine. I did > have a mistake in the letter. The secong time that the generic_swap() > function was given (the header that is) should have read: > generic_swap(void *a, void *b) > Sorry for this oversight. > > I do have a couple of questions, though... I think someone already mentioned that this was really a waste of time. Maybe he wasn't clear as to why. In C you have access to pointers so you would not want to actually move data from one place to another. Instead you would swap a pointer to the data. Small values like int's could be swapped since they could be smaller than a pointer, a pointer would be a waste. But you don't need a generic swap function for each int, float, etc. Just swap them. Large structures, arrays, character strings are best left where they are, swap the pointer. The most common need to swap something is while performing a bubble sort or the like. If your list is arranged as a linked list already with pointers, just swap the pointers. There's nothing really tough here that requires 286 assembly, C++, and ANSI is final already and no generic swap was added. Greg Galloway gg10@prism.gatech.edu