How to provide an implementation of memcpy
34
3
I am trying to write some bare metal code with a memset -style loop in it: for (int i = 0; i < N; ++i) { arr[i] = 0; } It is compiled with GCC and GCC is smart enough to turn that into a call to memset() . Unfortunately because it's bare metal I have no memset() (normally in libc) so I get a link error. undefined reference to `memset' It seems like the optimisation that does this transformation is -ftree-loop-distribute-patterns : Perform loop distribution of patterns that can be code generated with calls to a library. This flag is enabled by default at -O2 and higher, and by -fprofile-use and -fauto-profile . So one person's solution was to just lower the optimisation level. Not very satisfying. I also found this really helpful page th...