Skip to content

Instantly share code, notes, and snippets.

@objectx
Created March 27, 2012 00:51
Show Gist options
  • Save objectx/2211201 to your computer and use it in GitHub Desktop.
Save objectx/2211201 to your computer and use it in GitHub Desktop.
An annoying way to copy a region. Don't try this anymore.
#include <sys/types.h>
void copy (char *dst, char *src, size_t size) {
if (size == 0) {
return ;
}
size_t sz = size / 4 ;
switch (size % 4) {
while (sz-- != 0) {
default:
*dst++ = *src++ ;
case 3:
*dst++ = *src++ ;
case 2:
*dst++ = *src++ ;
case 1:
*dst++ = *src++ ;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment