I have a static structure p
defined in a C file like below (all the below code is in the same file). However, when I compile, I see that the compiler optimizes p
out (in the .o
file, hence this doesn't reach the linker). Here p
is not 'unused' and is written once, but not read back anywhere.
How does the compiler decide to optimize it out ? Can anyone point me to any documentation describing this?
static struct
{
int p1;
int p2;
}p;
static void foo(void) //this is getting inlined..
{
p.p1 = 10;
p.p2 = 20;
}
void foo1(void)
{
blah();
foo();
blah1();
}
If I make p
volatile, it is not getting optimized anyway.