Hi,
I want to keep unused constant in my code but I get strange initial value.
I use 3 variations but none of them initialize argument on left side by value 21 :
static uint32_t prm_sw_version __attribute__((used)) = 21;
static volatile uint32_t prm_sw_version_volatile __attribute__((used)) = 21;
static const uint32_t prm_sw_version_const __attribute__((used)) = 21;
Why are left side arguments not initialized ?
Thank you !
Solved! Go to Solution.
Hi Adam,
I also experienced the same problem as yours when I developed my project.
In the past when I use KDS, I use KEEP command in ld file to avoid variable being optimized.
MCUXpresso uses manage linker script, if we modify ld file by hand, we will loose the convenience of "manage linker script".
To avoid optimizing global variable, sometimes I wrote dummy code. For example, to avoid g_var being optimized:
int g_var;
main(){
volatile int dummy=0;
dummy=g_var;
...
}
Have a great day,
Jennie Zhang
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Adam,
I also experienced the same problem as yours when I developed my project.
In the past when I use KDS, I use KEEP command in ld file to avoid variable being optimized.
MCUXpresso uses manage linker script, if we modify ld file by hand, we will loose the convenience of "manage linker script".
To avoid optimizing global variable, sometimes I wrote dummy code. For example, to avoid g_var being optimized:
int g_var;
main(){
volatile int dummy=0;
dummy=g_var;
...
}
Have a great day,
Jennie Zhang
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Thank you !
If nothing in your code is actually using those variables, would suspect that they have actually been removed from your linked application (the used attribute doesn't actually do what you might expect in many cases).
Check the map file generated by the linker into the Debug (or Release) subdirectory of your project after doing a build to find out what has been discarded.
Regards,
MCUXpresso IDE Support