for loop variable optimization in C/C++ -


which faster in following 2 code snippets? , why?

declared loop index variable outside for statement:

size_t = 0; (i = 0; < 10; i++)  {  } 

and

declared loop index variable within for statement:

for (size_t = 0; < 10; i++)  {  } 

neither, equivalent , yield same machine code.

(the compiler remove redundant initialization of i twice first example.)

where variable declared has little performance , memory use.

for (size_t = 0; < 10; i++) considered readable.

for (i = 0; < 10; i++) has advantage can use i variable after loop done - makes sense when number of iterations variable.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -