From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f891f,44fe09bd8498caae,start X-Google-Attributes: gidf891f,public X-Google-Thread: 103376,c840deaa6965e67a X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-02-01 15:00:49 PST Path: nntp.gmd.de!Germany.EU.net!wizard.pn.com!satisfied.elf.com!news.mathworks.com!hookup!swrinde!ihnp4.ucsd.edu!network.ucsd.edu!mbk From: mbk@inls1.ucsd.edu (Matt Kennel) Newsgroups: comp.lang.ada,comp.lang.misc Subject: Re: Memory overwrite? Date: 1 Feb 1995 23:00:49 GMT Organization: Institute For Nonlinear Science, UCSD Message-ID: <3gp3r1$e0m@network.ucsd.edu> References: NNTP-Posting-Host: lyapunov.ucsd.edu Followups-To: comp.lang.misc X-Newsreader: TIN [version 1.1 PL8] Xref: nntp.gmd.de comp.lang.ada:18489 comp.lang.misc:10608 Date: 1995-02-01T23:00:49+00:00 List-Id: Robert A Duff (bobduff@world.std.com) wrote: : In article <3gehlo$i05@gnat.cs.nyu.edu>, Robert Dewar wrote: : >But just the fact that you are using two different I's does not seem : >to warrant a warning to me! : This mistake is so common, I think it deserves a warning. You've got : nothing better to do, right? ;-) : If you have a variable that is never initialized (whether it's used or : not), and an inner for loop index of the same name, that's when I would : give a warning about not needing to declare the for loop index. Of : course, a variable never initialized (or used) might deserve a warning : anyway, but if you just say "variable I never used", you will confuse : someone who thought you needed to declare I outside the for loop. To : me, it seems friendy to give a more specific message in the for-loop : case. This is gettting a little off topic but... Sather has an interesting take on this issue: you can declare and initialize variables anywhere an assignment is legal, but scopes are NOT nested. So if you try to do it again to the same identifier it will complain and not allow it. It allows you to "Put your declaration close to the use" (and thus lower the chance of uninitialized variables, and minimize confusion over things declared before there is any logical need or use for them) but lower the chance of "calling different things the same name adding to confusion" that a declaration close to use with nested scopes would often imply. example: loop e ::= collection.elt!; -- return elements of collection in sequence. process(e); -- a nested loop: loop -- e ::= something_else.elt!; -- NOT LEGAL, redeclares "e". end; end; ---- The "::=" means "declare static type of variable on left to be the same as static type of right side, and then perform the assignment. This is useful in situations like the above. You don't really want to denote the type of "e". All that you care is that "e" is compatible with the return type of the "elt!" call so that it can hold/reference a legal object. What's wrong with declaring it explicitly? Nothing. {You could have said e:TYPE:= right_hand_side just as easily}. Just that when you're in the early stages of development where the actual types that will be returned are undergoing big changes as the design evolves you don't have to spend time just mechanically changing the names of types in a billion places. : - Bob cheers Matt -- -Matt Kennel mbk@inls1.ucsd.edu -Institute for Nonlinear Science, University of California, San Diego -*** AD: Archive for nonlinear dynamics papers & programs: FTP to -*** lyapunov.ucsd.edu, username "anonymous".