Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!gatech!mcnc!ecsvax!dukeac!sbigham From: sbigham@dukeac.UUCP (Scott Bigham) Newsgroups: comp.lang.c Subject: Re: "for" loops (was Re: C++ vs. Modula Message-ID: <1211@dukeac.UUCP> Date: 2 Feb 89 19:52:16 GMT References: <1611@csuna.UUCP> <7800002@gistdev> Reply-To: sbigham@dukeac.UUCP (Scott Bigham) Organization: Academic Computing, Duke University, Durham, NC Lines: 49 In article <7800002@gistdev> flint@gistdev.UUCP writes: > >I've always felt that it should be the job of programming languages to let >me say what I want to do concisely, and then they should do it the way I >want. What you want, it seems, is a programming language that can read your mind. > Therefore, there is no reason I can see that the language should not >let you have an increment of .1, since it is quite clear exactly what I >want it to do in this case: Obvious to you. How do you explain it to the compiler? > the compiler ought to be able to see (easily) >that it needs to set up a dummy integer counter to actually control the >loop, and divide by 10 at the top of the loop for you to give you the index >you use. That's not at all obvious, and in many cases it's not even possible. How do you resolve this loop? for (i=0.0;i<100.0;i+=PI); In the general case, such optimizations as you describe would require lots of convolutions and aren't useful often enough to be worth it. If you really want the compiler to use an integer, tell it to. > By doing so, it allows experienced people to do less typing, and >protects beginners from their ignorance- you win both ways. Not necessarily what we want to do. If you shelter beginners from their mistakes, they can't learn from them. Remember: for every situation in which the compiler does exactly what you want, there are at least ten people who think the compiler should do it differently. >Flint Pellett, Global Information Systems Technology, Inc. >1800 Woodfield Drive, Savoy, IL 61874 (217) 352-1165 >INTERNET: flint%gistdev@uxc.cso.uiuc.edu >UUCP: {uunet,pur-ee,convex}!uiucuxc!gistdev!flint sbigham -- Scott Bigham "The opinions expressed above are Internet sbigham@dukeac.ac.duke.edu (c) 1989 Hacker Ltd. and cannot be USENET sbigham@dukeac.UUCP copied or distributed without a ...!mcnc!ecsgate!dukeac!sbigham Darn Good Reason."