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: 103376,8002154d2966e1a1 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-11-03 17:47:57 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeed.berkeley.edu!news-hog.berkeley.edu!ucberkeley!newshub.sdsu.edu!news-xfer.cox.net!cox.net!newsfeed1.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3DC5D1B7.1060707@acm.org> From: Jeffrey Carter User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.0.0) Gecko/20020530 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Local vs global variables in ADA References: <5Ldx9.3695$151.38236@weber.videotron.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 04 Nov 2002 01:47:02 GMT NNTP-Posting-Host: 63.184.0.151 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 1036374422 63.184.0.151 (Sun, 03 Nov 2002 17:47:02 PST) NNTP-Posting-Date: Sun, 03 Nov 2002 17:47:02 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:30333 Date: 2002-11-04T01:47:02+00:00 List-Id: Roger wrote: > Yes I'm an Ada newbie and have a questions about local and global variables. > When exactly is a variable said to be global? This is a good question. Unlike some languages, in which a variable is either global or local, Ada has various degrees of locality. This sometimes causes heated discussions between those who follow a strict, blind-obedience rule of no global variables and those with a better understanding of the matter. For example, a variable declared in a package body may be global to the subprograms in the package, but they are not visible outside the package. Knee-jerk rule following says these are not allowed because they're global variables. Actually, these are state variables for the package and perfectly acceptable. The only real global variables in Ada are those declared in the visible part of package specifications. These are a no-no. > > for example I have this code > --main procedure > Procedure Main Is > --If I declare a variable here will it be considered as > --global to the sub procedures? Yes. > --sub procedure > Procedure Sub > > Begin > > End Sub; > > > > Begin > --If I declare a variable here will it be considered as > --global to the sub procedure? > End Main; You can't declare a variable there without a block statement. Perhaps you meant begin -- Main declare -- variable declaration begin ... end; end Main; in which case you can have declarations there. Such declarations are not visible outside the block statement in which they are declared, so they are not visible to Sub. Not that Ada is not C, so your main procedure can have a more informative name than "Main" if you like. -- Jeff Carter "Monsieur Arthur King, who has the brain of a duck, you know." Monty Python & the Holy Grail