so you're implementing it's better not to use the extra variable in the for loop and instead go with type 1?

I've always wondered if we can use chars instead of ints in for loops since chars use less space than ints. Since the use of type casting is now supported by many compilers, I don't think that should matter anymore. Maybe some old Borland Turbo C++ compiler might support the short and tiny pointers and what not.
Funny thing is there isn't bool in thay old compiler. instead we have to use an int or char or enumerator (I don't prefer this) , etcetra to substitute this.

oskilian, where did you get that comparative info from or is it just your compiler?

>>reuse variables, clean them as less often as you can, always think about code complexity

reuse... It just seems to canabalistic, doesnt it? And it makes the flow absolutly horrible. I occassionally reuse vars for vital sections of code but in general I sacrifice the benefit for the benefit of being able to understand wtf is going on one month later.

>>I've always wondered if we can use chars instead of ints in for loops

Yes. Theres no difference between a char and a short besides the size.

Originally posted by lightatdawn >>reuse variables, clean them as less often as you can, always think about code complexity

reuse... It just seems to canabalistic, doesnt it? And it makes the flow absolutly horrible. I occassionally reuse vars for vital sections of code but in general I sacrifice the benefit for the benefit of being able to understand wtf is going on one month later.

>>I've always wondered if we can use chars instead of ints in for loops

Yes. Theres no difference between a char and a short besides the size.

yes, but how do I go by doing that?

Code:

char c;
for( ? )
{
//code
}

say I want to use indexing in a for loop using a char instead of a short: since a char obviously requires less memory versus an unsigned short int, wouldn't it better to use a char instead if we are only staying with the range 0 <= c <= 255? otherwise, I would stay with ints.

as for the above sample outline, how would you add such use with chars? if it works, wouldn't the memory size for the char be extended for the use of type casting the value back to int meaning the memory size of the char and int would be the same? if that is true, all this would be a waste of time.

Code:

// is this how you use chars for indexing in a for loop
char c;
for( c=char(0); c<char(10); c++)
{
cout<<int(c);
}