W
wkaras
I've compiled this code:
const int x0 = 10;
const int x1 = 20;
const int x2 = 30;
int x[] = { x2, x0, x1 };
struct Y
{
int i;
double d;
};
const Y y0 = {1, 1.0};
const Y y1 = {2, 2.0};
const Y y2 = {3, 3.0};
Y y[] = { y1, y0, y2 };
int z[] = { y1.i, y0.i, y2.i };
with a couple of compilers, with the highest possible optimization,
and looked at the disassembled object code. With both compilers,
only the x array is initialized from the load image. Move instructions
are generated to initialize both y and z. Why is it hard for the
compiler to initialize all of this from the load image, without having
to execute any init code at run time?
const int x0 = 10;
const int x1 = 20;
const int x2 = 30;
int x[] = { x2, x0, x1 };
struct Y
{
int i;
double d;
};
const Y y0 = {1, 1.0};
const Y y1 = {2, 2.0};
const Y y2 = {3, 3.0};
Y y[] = { y1, y0, y2 };
int z[] = { y1.i, y0.i, y2.i };
with a couple of compilers, with the highest possible optimization,
and looked at the disassembled object code. With both compilers,
only the x array is initialized from the load image. Move instructions
are generated to initialize both y and z. Why is it hard for the
compiler to initialize all of this from the load image, without having
to execute any init code at run time?