Xref: utzoo comp.lang.modula2:1259 comp.lang.c:16047 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!decwrl!labrea!polya!Polya.Stanford.EDU From: crew@Polya.Stanford.EDU (Roger Crew) Newsgroups: comp.lang.modula2,comp.lang.c Subject: Re: "for" loops (was Re: C++ vs. Modula2) Message-ID: <6680@polya.Stanford.EDU> Date: 6 Feb 89 18:39:31 GMT References: <19579@agate.BERKELEY.EDU> <8515@lanl.gov> <6419@polya.Stanford.EDU> <1004@ubu.warwick.UUCP> Sender: crew@polya.Stanford.EDU Reply-To: crew@Polya.Stanford.EDU (Roger Crew) Followup-To: comp.lang.modula2 Organization: Stanford University Computer Science Dept. Lines: 51 In-reply-to: geoff@warwick.UUCP (Geoff Rimmer) In article <1004@ubu.warwick.UUCP>, geoff@warwick (Geoff Rimmer) writes: > In article <6419@polya.Stanford.EDU> crew@Polya.Stanford.EDU (Roger Crew) writes: > >Here's a quiz: > >How would you write the following in C? > > > > VAR a, b, c : Char; > > ... > > FOR c = a TO b DO ... END; > > [ ... yup, this discussion ...] > > What a stupid question. If you are going to count from 0 to 255, you > wouldn't use char in the first place - you'd use unsigned char, or > int. I can't see what you're getting at, at all. I'll grant that, for the benefit of compilers that *have* signed chars, I actually did intend to say ``unsigned char'' rather than ``char''. The fact of the matter is, however, that unsigned char a; for( c=0; c<=255; ++c) {...} still doesn't work. You can try it if you like, or you can read the submissions from the other 10 posters who understand what's going on... The fact that I was using chars signed or unsigned is irrelevant to the point I was trying to make, namely that the semantics of C for-loops and Modula/Pascal for-loops are entirely different -- it is not simply a case of one being more general than the other. While it's fairly obvious that a general C for-loop often can't be written as a Modula for-loop, it's not so obvious (or at least, *I* didn't think it was completely obvious...) that to do a general Modula for-loop in C *also* requires strange contortions. As for *why* I'd want to be counting with chars, just consider any application requiring some kind of array indexed by chars, e.g., VAR font : ARRAY Char OF Bitmap; It's an obvious thing to do in Modula. I suppose this also illustrates the danger of carrying over one languages way of thinking into another, a problem that does not confine itself to for-loops. > Go back to writing Fortran. Let the *real* programmers use C. :-) I'll let this statement speak for itself. :=) -- Roger Crew ``Beam Wesley into the sun!'' Usenet: {arpa gateways, decwrl, uunet, rutgers}!polya.stanford.edu!crew Internet: crew@polya.Stanford.EDU