Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!uwvax!sevenlayer.cs.wisc.edu!bothner From: bothner@sevenlayer.cs.wisc.edu (Per Bothner) Newsgroups: comp.lang.c++ Subject: Re: C++ coding standards (Comment needed) Keywords: standard,variables Message-ID: <11190@spool.cs.wisc.edu> Date: 7 Sep 90 19:59:19 GMT References: <56642@microsoft.UUCP> <41673@think.Think.COM> <56953@microsoft.UUCP> <2675@dataio.Data-IO.COM> <57167@microsoft.UUCP> Sender: news@spool.cs.wisc.edu Reply-To: bothner@sevenlayer.cs.wisc.edu (Per Bothner) Organization: University of Wisconsin--Madison Lines: 24 jimad@microsoft.UUCP (Jim ADCOCK) writes: >| func() >| { { int i; .... } >| { int j; .... } >| } >| >|i and j's live ranges do not overlap, so they can (and do with some >|compilers) share the same storage location. > >Yes, but C++ defines that destruction of named objects be on exit from >scope [with few exceptions], thus greatly restricting a compilers from >performing these optimizations on other than primitives. Huh? "On exit from scope" means "at the end of the block" in this case, so there is no problem allocating i and j to the same location, even if their class(es) have destructors. Construction and destruction must by definition delimit an object's live range. Two variables in the same function, but defined in non-intersection blocks do not have overlapping live ranges. And can therefore share storage locations. -- --Per Bothner bothner@cs.wisc.edu Computer Sciences Dept, U. of Wisconsin-Madison