ok
the original C code:
Code:
/*
* File: memswap.c
* Author: thames
*
* Created on 7 de Janeiro de 2013, 12:55
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int swap(void* x, void* y, size_t size)
{
void* tmp;
if( (tmp = malloc(size)) == NULL)
return -1;
memcpy(tmp, x, size);
memcpy(x, y, size);
memcpy(y, tmp, size);
free(tmp);
return 0;
}
int main(int argc, char** argv) {
int x = 10;
int y = 20;
size_t size = sizeof(int);
if(swap(&x, &y, size) == 0)
{
printf("%d %d\n", x, y);
return EXIT_SUCCESS;
}
else
{
printf("%s\n", "An error has occurred.");
return EXIT_FAILURE;
}
}
I already removed the C++ swap code I coded from my toolkit