I remember reading somewhere that it is better to use integers as loop counter variables rather than char or short. If yes, why? Does it provide any optimization benefits?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Generally, the compiler will make
intto be a good size for putting into one of your CPU’s general purpose registers. That generally leads to fast access.Of course there’s no guarantee of anything. The compiler is free to do a lot of things, including, I would guess, promote some of your code that uses
charto some larger type. So the difference might not even matter.Really, for the answer that’s true for your compiler, you should look at the assembly it outputs.