Question.10
A developer uses std::function to store a capturing lambda:
std::function
#include <functional> std::function<void()> callback; void setup() { int data[16]; callback = [data]() { process(data); }; }
Why is this risky in firmware?
Select Answer
std::function is not available on embedded compilers
std::function typically uses heap allocation (malloc) to store the captured data (64 bytes here) -- this introduces fragmentation, non-deterministic timing, and potential allocation failure
std::function is slower than function pointers
The lambda captures too many variables