By specifying volatile and zeroing out the memory in a loop, you're guaranteed that the compiler won't optimize away the zeroing. But if you want something faster, you need to get cleverer, because there's no universal "optimize this way but not that way" command.
#pragma GCC push_options
#pragma GCC optimize ("O0")
memset(a, 0, 3);
#pragma GCC pop_options
Edit: buried at the bottom of that post is another method: