From: "A. Sinan Unur" Newsgroups: comp.os.msdos.djgpp Subject: Re: For loop problem Date: Tue, 07 Apr 1998 19:59:55 -0400 Organization: Cornell University (http://www.cornell.edu/) Lines: 41 Sender: asu1 AT cornell DOT edu (Verified) Message-ID: <352ABDFB.FA40D866@cornell.edu> References: <3527FEA6 DOT 54FA AT vegas DOT infi DOT net> NNTP-Posting-Host: cu-dialup-2126.cit.cornell.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk James W Sager Iii wrote: > > Excerpts from netnews.comp.os.msdos.djgpp: 5-Apr-98 For loop problem > by > Simz AT vegas DOT infi DOT net > > unsigned char index = 0; > > unsigned char array[256]; > > for (index = 0; index < 256; index++) > > array[index] = index; > > Ok, C++ is not exactly a strong type language. > That is, it will allow char to int to pointers > with the compiler bitching at you. > I'm not sure why the above code doesn't work, but I know > it would be 'nicer' if index was an integer. > And I'm just guessing you don't need the unsigned part. > I'm pretty sure chars automatically give you 0 to 255 by default. please, if you are going to post stuff like this, try comp.lang.c.bs or something else. if you don't know something, don't feel obligated to give an answer, learn. using int is not about being 'nice'. see the other responses to this post (which was off-topic to begin with) as to why it is not a good idea to use unsigned char as an index type. chars give you -128 to 127 on this platform, a fact you could have easily checked. keep in mind that computers are pretty deterministic beasts (at least at this level), and GIGO is the most basic rule. -- ---------------------------------------------------------------------- A. Sinan Unur Department of Policy Analysis and Management, College of Human Ecology, Cornell University, Ithaca, NY 14853, USA mailto:sinan DOT unur AT cornell DOT edu http://www.people.cornell.edu/pages/asu1/