What in swaps name is this?
obviously it doesn't swap, a and b are local and vanishes when the function 
returns.



void swapgen(void *a, void *b, size_t size)
{
  char *ca, *cb;
  int i;
  ca = (char *)a;
  cb = (char *)b;
  for(i=0;i<size;*(ca+i)^=*(cb+i),*(cb+i)^=*(ca+i),*(ca+i)^=*(cb+i),++i);
}

void swap0(void *A, void *B)
{
   void *Temp;
 
  Temp = A;
  A = B;
  B = Temp;
};

void swap1(void **x, void **y) {
    void *t = *x;
    *x = *y;
    *y = t;
}


void swap2(int *a,int* b){
    
    int* temp;
    temp=a;    
    a=b;    
    b=temp;
    
}
void swap3(int *a,int*b){
    
    int* temp;
    temp= a;    
    a=b;    
    b=temp;
    
}






________________________________
From: Paul Herring <[email protected]>
To: [email protected]
Sent: Wed, February 17, 2010 3:35:38 PM
Subject: Re: [c-prog] swap two numbers

  
On Wed, Feb 17, 2010 at 12:21 PM, sweet_heart _625
<sweet_heart_ 6...@yahoo. com> wrote:
> The best way of swaping is

This has to be one of the worst ways of swapping.

> swap(int a,int b)
> {
>    a=a+b;
>    b=a-b;
>    a=a-b;
> }

No it isn't.
1) It may fail with overflow errors
2) Calling this in a program WON'T ACTUALLY SWAP ANYTHING the calling
code wants it to.

Read <http://tech. groups.yahoo. com/group/ c-prog/files/ html/swapnotemp. html>
(or <http://avsharath. googlepages. com/swapnotemp. html> if you can't
get the first copy) LIKE YOU WERE TOLD TO DO AT THE TOP OF THE THREAD!

-- 
PJH

http://shabbleland. myminicity. com/env
http://www.chavgang s.com/register. php?referer= 9375

 


      

[Non-text portions of this message have been removed]

Reply via email to