4 ms·
There are non-portable means in most implementations (via asm extensions). Obviously, this is more work and much less convenient than a volatile keyword that gi
by sokoloff 7y ago
There are non-portable means in most implementations (via asm extensions). Obviously, this is more work and much less convenient than a volatile keyword that gives you the functionality.
- saagarjha 7y agoDoesn’t this need volatile itself since the compiler can’t introspect what the assembly is doing?
- jacobush 7y agoEhm, no, once you are in assembly, you do whatever you want to do. There is no compiler to mess things up for you. (Although, it's leaving that to you hehe... :-)
- notimetorelax 7y agoI think the compiler still needs to know that the value might be modified from the outside. Otherwise it might optimize the read operation away from the codepath.
- simcop2387 7y agoYou'd have to do all the reads in ASM too then, but it would still be possible. It'd be terrible ergonomically.
- srfilipek 7y agoYes, that is part of creating inline assembly in C or C++ code: http://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html http://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html