I do understand that it's generally unsafe to memcpy to overlapping regions and I do understand the reasons. But my question is: is it generally safe to do something like that?
#include <stdio.h>
#include <string.h>
int main(void) {
int a = 5;
memcpy(&a, &a, sizeof a);
printf("%d", a);
return 0;
}
If not, in which hardware/software configurations can I assume it to be safe?
edit1: so I'll refine my question: would the usual* implementation of this function consider it safe? (outside of C standards of course)
edit2: I do know the problem could be solved easily, but the question aroused by the strange use case, which is not directly covered by other answers.
*for usual I mean the implementation of most used and deployed systems (e.g. linux, windows ...)