I've already posted about this yesterday, but that was with a C compiler. What does one have to do with g++ to make sure that foo is properly inlined? I need that information for an upcoming primer about compiler optimizations:
typedef struct{const unsigned a;const unsigned b;}immut_t;
typedef struct{int done;}mut_t;
typedef struct
{
const immut_t immu;
mut_t mu;
}my_struct;
static my_struct array[] =
{
{{1,2},{0}},{{3,4},{0}},
{{5,6},{0}},{{7,8},{0}}
};
unsigned long long foo(void)
{
unsigned long long ret = 0;
for(unsigned i = 0;i < ARRAY_SIZE(array);i++)
ret += array[i].immu.a * 2 + array[i].immu.b;
return ret;
}
void bar(void)
{
for(unsigned i = 0;i < ARRAY_SIZE(array);i++)
array[i].mu.done = 1;
}