delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/07/11/10:30:29

From: Martin Ambuhl <mambuhl AT earthlink DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: it's amazing (at least for me)
Date: Sun, 11 Jul 1999 01:46:47 -0400
References: <378618ca DOT 3495674 AT news DOT telepac DOT pt>
X-Posted-Path-Was: not-for-mail
X-Accept-Language: en,fr,de,zh,en-GB,de-CH,fr-CH,zh-CN,cs,el,ja,ru
X-ELN-Date: 11 Jul 1999 05:45:19 GMT
X-ELN-Insert-Date: Sat Jul 10 22:55:02 1999
Organization: Nocturnal Aviation
Lines: 45
Mime-Version: 1.0
NNTP-Posting-Host: dialup-209.246.75.37.newyork2.level3.net
Message-ID: <37882FC7.986703CD@earthlink.net>
X-Mailer: Mozilla 4.61 [en] (Win95; U)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

aperes 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

The maximum value an unsigned char can hold is 255.  
unsigned char i = 255;
i++;
/* now i == 0 */

So i<256 is always true.



> 
> 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;
> }

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019