Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
参考线程:memmove implementation in C,我不明白为什么 2 个不同的变量会有内存重叠?即这是编译器将相同的“公共空间”分配给2个不同变量的正常情况,为什么编译器在这种情况下使用此策略?
与编译器无关。考虑以下:
int x[100]; memmove(&x[1], &x[0], 99*sizeof(int));
这与编译器创建重叠的变量无关。只是规范memmove说它必须工作,即使源和目标重叠。如果两者没有重叠的机会,您通常想要使用memcpy,这通常会更快,但如果它们重叠,则会给出未定义的行为。
memmove
memcpy