0

what is the difference between statements below?

X = Y*0;
   X = 0;

a kind of optimization problem.

5
Contributors
5
Replies
6
Views
10 Years
Discussion Span
Last Post by Rashakil Fol
0

I think you can see the difference right there for yourself. This has nothing to do with optimization, unless you enable the -fretarded flag on your compiler.

0

I've never really heard of optimization on a high level programming language. In assembly perhaps.
So I would expect that X = 0 is more efficent that X = Y * 0;
The issue lies with memory access and compution. X = 0 accesses memory once where as the X = Y * 0 access memory twice and performs a calculation. If you look at the assembly commands to carry out these operations, you'll see the actual costs involved.

0

You don't optimize wrong code.. You correct it..
Why would anyone do x= y * 0; if they want to set x to 0 ?!

0

You might have x = y * CONSTANT where #define CONSTANT 0 is located someplace. That's how you could get that in your code.

Whether x = y * 0 is compiled to anything different than x = 0 is compiled to depends on the compiler.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.