In C programming, a volatile variable can change its value unexpectedly due to multiple threads, modification by an external device, or an external process. The tutorial analyzes and compares how the assembly output, compiled from C source code, differs based on the use of a volatile int variable and a non-volatile int variable. Volatile variables can affect compiler optimizations and are frequently used in embedded systems where the most current variable value is crucial. The choice to use volatile or not depends on the program's specific requirements and the expected behavior of the variables.
Tag: Memory
Structure Alignment
CPU accesses memory by a single memory word at a time. Depending processor architecture, a word size varies - 8, 16, 24, 32, or 64 bits. Special purpose processors, such as DSPs may use other sizes, ie. 9, 12, 18, 24, 26, 36, 39, 40, 48, and 60 bits.Memory is byte addressable and arranged sequentially.… Continue reading Structure Alignment
Oops ! Volatile
While translating source code to machine code, compiler applies various optimisations. Compiler cleans excess machine code to reduce executable size and increase speed of execution, saves memory, CPU cycle etc. if a variable needs to be changed from outside compiler should not apply optimisation, since an optimisation might not check the variable at all in… Continue reading Oops ! Volatile
Memory Pinning
Memmory pinning - what , why, how, theory and resources