Mail Archives: djgpp/1998/04/05/22:16:49
Simz wrote:
>
> When ever I try to use a for loop in DJGPP with a char (or any type for
> that matter), the loop never stops when I try to loop to the max value
> that type can hold. For example
>
> unsigned char index = 0;
> unsigned char array[256];
> for (index = 0; index < 256; index++)
> array[index] = index;
Use a larger type. What you describe will not work with any C compiler,
much less djgpp. And since array indexes are ints, there's no reason
not to use an int in the loop instead of a char. Putting an int into a
char array is no problem; it's an implicit typecast. I should also
mention that initializing index and then setting it in the for loop is
redundant.
unsigned char array[256];
int index;
for ( index = 0; index < 256; index++ )
array[index] = index; /* or (char) index if it makes you
feel better */
hth
--
---------------------------------------------------------------------
| John M. Aldrich | "Animals can be driven crazy by pla- |
| aka Fighteer I | cing too many in too small a pen. |
| mailto:fighteer AT cs DOT com | Homo sapiens is the only animal that |
| http://www.cs.com/fighteer | voluntarily does this to himself." |
---------------------------------------------------------------------
- Raw text -