3 ms·
memcpy is usually treated as an intrinsic and compiled to efficient code when the size is a compile-time constant even in -O0. It is one of the few functions in
by Asooka 4y ago
memcpy is usually treated as an intrinsic and compiled to efficient code when the size is a compile-time constant even in -O0. It is one of the few functions in the standard library that I see as already written to be the best version possible. The one deficiency is that if your ranges overlap, the result is undefined, but you can use memmove instead.
- jenadine 4y agoAnd vice versa. The compiler can detect a loop and replace it by a call to memcpy https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56888 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56888
- CyberDildonics 4y agoThis is actually a big problem and a silly transformation in my opinion. You can write a one line loop that copies memory and suddenly your compiler needs to link with the standard library even if you're trying to avoid it.
- jjnoakes 4y agoYou might want -ffreestanding in those cases.