From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 21 Sep 92 16:51:08 GMT From: caen!uvaarpa!software.org!smithd@uunet.uu.net (Doug Smith) Subject: Re: Using Global Variables Message-ID: <1992Sep21.165108.11129@software.org> List-Id: In article <16864C1E7.M19481@mwvm.mitre.org> M19481@mwvm.mitre.org writes: > In article <1992Sep16.152620.9286@nosc.mil> > sampson@nosc.mil (Charles H. Sampson) writes: > > > > >In article <15390@suns5.crosfield.co.uk> pdg@crosfield.co.uk (paul goffin) > >writes (in an article on Ada compiler pricing): > > > >>So what did I mean by cost? Well, apart from the training costs > >>and the cost of setting up development systems that act>>Ada, (New compiler driving scripts, new way of addressing hardware, > >>new way of managing "global variables" - Yes, nasty as they are, > >>you do sometimes have to use global variables in the real world!) > >>there was a nasty shock in the price of the compilers. > > > > I'd like to hear more about this need to use global variables in > >the real world, from Mr. Goffin and anyone else. I can't remember the > >last time I used one in an Ada project, and I think what I do is pretty > >real world stuff. (Well, I do contract to the U. S. Navy, but that's > >close.) > > > > Charlie > > The main reason I've heard used to justify the use of global variables is > performance of a real-time system. The argument goes that the overhead of > parameter passing is just too high to meet the performance requirements on > the target machine (which cannot be changed), hence global variables. Now > you may argue that the target machine should have been chosen more wisely, > or the choice delayed until after the software was totally developed so as > to be able to pick the right size machine -- but I imagine that that's what > Mr. Goffin had in mind when he used the term "real world." > > David - dhite@mitre.org OK. Let's get specific. Assuming that having to `with' a package does not violate the definition of global, the following is definitely the declaration of a global variable: package Contains_Global is Global_Variable : Integer; end Contains_Global; Now I can effectively convert this to declare the variable inside the package body, but instead of assignment (a predefined procedure with special semantics), I must provide my own procedures to access it: package Convert_Global is procedure Put (Value : in Integer); procedure Get (Value : out Integer); pragma Inline (Put, Get); end Convert_Global; package body Convert_Global is Is_This_A_Global_Variable : Integer; ----------- What do you say? procedure Put (Value : in Integer) is begin Is_This_A_Global_Variable := Value; end Put; procedure Get (Value : out Integer) is begin Value := Is_This_A_Global_Variable; end Get; end Convert_Global; In an attempt to limit the potential explosion of discussion about why one is better than the other--let's try to define the term `Global' first! What is the Integer declared inside the package body? Doug smithd@software.org