So I am trying to write my own macro version of a memory copy implementation, yet for some reason it's exiting with non zero status for some reason.
#include <stdio.h>
#include <stdlib.h>
#define BTools_WRITE(dest, src, n) for (size_t i = 0;i<n;i++) { \
*(unsigned char*)(dest++) = *(unsigned char*)(src++); \
}
int main(void) {
char* f = "Hello sir!";
char* u = "4444";
void* fptr = f;
void* uptr = u;
int g = 4;
BTools_WRITE(fptr, uptr, g);
printf("%s\n", f);
return 0;
}
I have tried changing the for loop to while loop, or putting a do-while loop around the whole macro, it always returns with non-zero status. How can I fix this? Can this be done with just a macro?