Run the following without and with compiler optimization (PC rel 7)
// PC7 memmove/set test #2
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void me_move(char* ato, char* afrom, int u)
{ if (afrom < ato) // down
{ afrom += u, ato += u;
while (u--) { *--ato = *--afrom; } }
else // up
{ while (u--) { *ato++ = *afrom++; } }
}
int main(void)
{ char *str; int i;
str = malloc(4);
strcpy(str,"abc");
printf("lib moving %s :",str);
memmove(str+1,str,2);
printf("\naab ? %s",str);
if (strcmp(str,"aab")) printf("\t<< error");
memmove(str,str+1,2);
printf("\nabb ? %s",str);
if (strcmp(str,"abb")) printf("\t<< error");
strcpy(str,"abc");
printf("\n\nme moving %s :",str);
me_move(str+1,str,2);
printf("\naab ? %s",str);
if (strcmp(str,"aab")) printf("\t<< error");
me_move(str,str+1,2);
printf("\nabb ? %s\n",str);
if (strcmp(str,"abb")) printf("\t<< error");
memset(str,-1,4);
printf("\nlib filling :");
i = *(int*)str;
printf("\n-1 ? %d",i);
if (i != -1) printf("\t<< error");
puts("");
return 0;
}