468,468 Members | 2,686 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,468 developers. It's quick & easy.

evaluating builtin [] during initialization

It seems like it would not be hard for the optimizer to generate the
same
object code from this source code:

int x[] = { 3, 6, 9 };
int y = x[1];

as it does from this source code:

int x[] = { 3, 6, 9 };
int y = 6;

But it tried two compilers, with optimization enabled, and both
generated
"pre-main" executable code to initialize y (when it's assinged from
x[1]).

Anyone seen a compiler that does optimize out builtin [] in
initializers?
Or, anyone know why it is hard/bad to optimize [] out?

Jul 5 '06 #1
1 965
posted:

int x[] = { 3, 6, 9 };
int y = x[1];


Try:

int const x[] = { 3, 6, 9 };
And see if it makes a difference. (Or have you already tried that, and are
now experimenting with non-const arrays... ?)

--

Frederick Gotham
Jul 5 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Stephen Ferg | last post: by
11 posts views Thread by Rangi Keen | last post: by
6 posts views Thread by Anders K. Olsen | last post: by
4 posts views Thread by Pål Andreassen | last post: by
reply views Thread by satishwise | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.