Hi,
We are working on STM32G070 micro-controller. Our code size is approximately 75KB. We are using Embedded C++ language, Keil uvision version 5 with code optimization level 2.
We were trying to reduce the code size and we observed some strange things during compilation as below.
1. If I remove one function call from a function, the code size is increased by over 100 Bytes.
Expected: Removing one function call inside a function shall reduce the code size.
2. if we add a function call, code size is increased by over 100 bytes.
Expected: Code size shall be increased by maximum 10-20 bytes only as this function call was already made earlier from other functions in same file.
Do you know the reason for the above strange behavior?
Gagan Gupta said:2. if we add a function call, code size is increased by over 100 bytes.
Optimization is a big topic and you need to learn a fair bit to see what the best strategy is. In case #2, is the function inlined?
Yes, my function was defined inside the class. However I observed the same behaviour even if I define the function outside the class and specifically no inline.
Why guess? Use tools that examine the binary (objdump, nm, etc), and/or the output from the various build steps (linker map, assembly listing) and figure out exactly where the extra space is going.