Sincerely i didn't understand your code,im new to programming.
Usually, even if not used, the variables are stored in memory.
Karlwakim
Junior Poster in Training
94 posts since Dec 2011
Reputation Points: 27
Solved Threads: 2
Skill Endorsements: 0
I hope I'm posting in the right forum :)
I'm primarily concerned with C compilers and sun's JDK, but general info is more than welcome (Documentation for self-education as well).
Well, if i wrote a program like
int i = 5
printf("i is $d", i);
Would i=5 be stored separately in memory, or would it exactly the same the following?
printf("i is 5");
(perhaps ("i is $d", 5) is more accurate)
If not, one might balance readablity/maintainability against performance (small improvement perhaps, but I'm a sucker for learning these things, if not using them :) )
An optimizing compiler would likely choose your final option, assuming there's nothing in the code that would require i to exist as an actual entity. There are a huge number of factors involved when it comes to optimization though, so without a full example it's hard to tell you what the possible outcomes are.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,483
Solved Threads: 1,407
Skill Endorsements: 55
I'm guessing with gcc there will be no optimization, unless called with -O or similar parameters?
It's best not to guess. GCC is very aggressive when it comes to optimization, so a test using assembly output would be the better approach.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,483
Solved Threads: 1,407
Skill Endorsements: 55
Question Answered as of 1 Year Ago by
Narue
and
Karlwakim