Path: utzoo!mnetor!uunet!husc6!bloom-beacon!mit-eddie!uw-beaver!cornell!rochester!PT.CS.CMU.EDU!sei!sei.cmu.edu!firth From: firth@sei.cmu.edu (Robert Firth) Newsgroups: comp.lang.pascal Subject: Re: Global variables Message-ID: <4770@aw.sei.cmu.edu> Date: 29 Mar 88 13:47:10 GMT References: <12654@brl-adm.ARPA> <529@taux01.UUCP> Sender: netnews@sei.cmu.edu Reply-To: firth@bd.sei.cmu.edu.UUCP (Robert Firth) Organization: Carnegie-Mellon University, SEI, Pgh, Pa Lines: 18 Keywords: gloabl optimizing compilers In article <529@taux01.UUCP> orr@taux01.UUCP (Orr Michael ) writes: >As one of a team of compiler-writers, including a pascal compiler, >let me note that global variables reduce the compiler's room for >optimization. this is because any time you erite through a pointer, >potentially you may be changing the value of any global var... I don't think that's right. For example, in Pascal, an explicit pointer (^Thing) cannot point anywhere except into the heap, ie at an object created by NEW. It cannot alias any global variable. That leaves only VAR parameters as potential aliases. Even here, a VAR parameter of one type (VAR p: ThingA) cannot alias a global variable of any other type (VAR g: ThingB). The extent to which this matters depends on people's coding style, but with good Pascal programs (lots of different types) the amount of possible aliasing is less than 5% (ie for any pointer you know it cannot alias 95% or more of globals in scope).