2 ms·
Interesting About the memset bug, I wonder if this couldn't be solved by some kind of compiler directive in the function signature saying "you can't remove thi
by raverbashing 13y ago
Interesting
About the memset bug, I wonder if this couldn't be solved by some kind of compiler directive in the function signature saying "you can't remove this" (or something to that effect)
- justincormack 13y agoWell he mentions RtlSecureZeroMemory(), which must be a Windows thing, but clearly all compilers need some methods of dealing with this thats easy to do and can't be optimised away.
- Someone 13y agoYou don't need such a _compiler_ directive. The compiler can only optimize the call away because it can assume that std::memset does what the standard proscribes. Whenever you call an external function that is not in the standard library, the compiler can't know what it does and, hence, can't optimize it away. The linker, on the other hand, might do across-library optimizations that lead to it removing the call. So, at worst, you need a linker directive. Also, I am not sure you want this tagged to the function signature. There may be cases where optimizing the call away is perfectly valid.
- mitchty 13y agoThats why C11 has memset_s. http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1381.pdf http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1381.pdf
- raverbashing 13y agoThis is a good writeup, thanks
- lazyjones 13y agoFor gcc, there is this (to be used after the memset() call): asm volatile("" : : : "memory"); (see https://en.wikipedia.org/wiki/Memory_ordering#Memory_barrier_types https://en.wikipedia.org/wiki/Memory_ordering#Memory_barrier...)