Then size of result exe file is changed (build variant - release). This is my compiler args qcc -V4.2.4,gcc_ntox86 -c -Wc,-Wall -Wc,-Wno-parentheses -O -w9 -O0 -fno-inline-functions -DNDEBUG -DBUILDENV_qss. As you see I specially turn off optimizer. (In Momentics → Project Properties → Compiler → No optimize).
Please help me out Why result size of executable was changed???
Volatile is an important message to the compiler which concerns optimization. Here’s a simple example.
i = 0;
if (i > 1000000)
As it stands, the compiler could create code like this.
load ax-register with 0
if (ax-register > 1000000
store ax-register to i;
jump to loop
However if you add volatile to the int i, this code is no longer valid.
Instead, either the memory location of i must be incremented or after each increment of the ax-register it would need to be stored. That’s because another thread or context (eg. interrupt handler) could change the value of i.
Writing an optimizing compiler is a tricky endeavor. A simplification could be eliminating certain optimizations just because “volatile” appears in the code. This would not be optimal, but it would work.
Using registers of the CPU isn’t an optimization. So, if you turn off optimization, still the compiler will make use of CPU registers - that’s what they are for. Only when you specify volatile, CPU registers will not be used for the volatile var. So different code will be generated and that explains why the executable length is different.