Skip to content

Instantly share code, notes, and snippets.

@bynect
Last active August 23, 2021 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bynect/7032ba8de7cf5e5125fc15ad840a28a7 to your computer and use it in GitHub Desktop.
Save bynect/7032ba8de7cf5e5125fc15ad840a28a7 to your computer and use it in GitHub Desktop.
Memswap implementation in ISO C.
#ifndef MEMSWAP_H
#define MEMSWAP_H
static inline void
memswap(void *restrict aptr, void *restrict bptr, size_t len)
{
register unsigned char *a = aptr;
register unsigned char *b = bptr;
register unsigned char t;
while (len--)
{
t = *a;
*a++ = *b;
*b++ = t;
}
}
#endif /* MEMSWAP_H */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment