Mail Archives: djgpp/1999/07/10/17:15:28
aperes (ajps AT mail DOT telepac DOT pt) wrote:
: In this little C program if i change the type of variable k (in setup
: function) to byte the program don't work. Can anyone explain me why?
: Thanks
: 
: APeres.
: 
: ------------------------------------------------------------------------------------
: typedef  unsigned char  byte;
: typedef  unsigned char  pallette[256][3];
: 
: void setup(pallette);
: 
: int main(void)
: {
:    int i;
:    pallette pall;
: 
:    setup(pall);
: 
:    for(i=0; i < 256; i++)
:       printf("%d ------- %d\n", i, pall[i][0]);
: 
:    return 1;
: 
: }
: 
: void setup(pallette pall)
: {
:    int k;
: 
:       for(k=0; k < 256; k++)
:       pall[k][0] = pall[k][1] = pall[k][2] = i;
: }
Alas it's not compilable. In setup() i is undeclared.
Let's I change that i to k, which is what I think you meant.
Now as you say it works with "int k;"
But it also work in the case of "byte k;". The problem is you have a
missguided idea of what "it works" means in this case. If k is an
unsigned char then k's maximum value is 255, hence the for loop's
continuation expression is always true, which leads to endless
looping.
If you had run your program in a debugger you'd seen this (which I had
to do to realise what was happening).
Another little problem (which is unrelated) is that you haven't
#included stdio.h. This you would have found if you were using the
gcc flag "-Wall".
Skunk Anansie, Paranoid & Sunburnt,
							MartinS
- Raw text -