> Variables and constants that don't get used get ignored by
> the
> compiler and don't take up more space.

That's true, but the truth is even better. Constants never take any space. (If 
they are not constant arrays AND at least once referred to with a variable 
index. In that case they use code memory, not data memory however).

Constants do not exist in machine language. At any place a constant occurs in 
the high-level-program, it is replaced with its literal value in the machine 
program.

I had thought that the compiler was even cleverer, but I had a look at jal 2.4n 
(compiled Jun  2 2010), and it does not optimize that far:

If a variable is set to a literal value only once (or set to the same literal 
value again), and after that it is just read, it could be converted to a 
constant. Or, to that literal value, and therefore completely optimized away, 
using not a single byte. But I have not seen that optimization, if there's a 
variable, and it is read at least once, it will end up as a variable in the asm 
code and consume space, even if its value is constant all the time.

Greets,
Kiste


-- 
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en.

Reply via email to