Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdint.h>
- #include <math.h>
- #include <assert.h>
- #include <memory.h>
- inline void swap(void* a, void* b, size_t size) {
- for (; size % sizeof(long); size--) {
- char temp = *(char*)a;
- *(((char*)a)++) = *(char*)b;
- *(((char*)b)++) = temp;
- };
- for (; size; size -= sizeof(long)) {
- long temp = *(long*)a;
- *(((long*)a)++) = *(long*)b;
- *(((long*)b)++) = temp;
- };
- }
- inline void swap_s(void* a, void* b, size_t size) {
- if (abs((char*)a - b) >= size) {
- long temp;
- for (; size % sizeof(long); size--) {
- temp = *(char*)a;
- *(((char*)a)++) = *(char*)b;
- *(((char*)b)++) = temp;
- };
- for (; size; size -= sizeof(long)) {
- temp = *(long*)a;
- *(((long*)a)++) = *(long*)b;
- *(((long*)b)++) = temp;
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement