Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!apple!bionet!agate!ucbvax!hplabs!sm.unisys.com!csun!polyslo!cquenel From: cquenel@polyslo.CalPoly.EDU (Suspended in Gaffa) Newsgroups: comp.std.c Subject: Taking the address of local variables Message-ID: <6037@polyslo.CalPoly.EDU> Date: 20 Nov 88 21:58:41 GMT References: <6472@june.cs.washington.edu> Reply-To: cquenel@polyslo.CalPoly.EDU (Suspended in Gaffa) Organization: Chronological Order Lines: 37 In article <6472@june.cs.washington.edu> pardo@cs.washington.edu (David Keppel) writes: [stuff about taking the address of a local variable] I believe that the way this is COMMONLY dealt with is the following: When the compiler sees the address taken of a local variable, it is forced to treat this as basically "volatile" in a way. All modifications to that variable must be written out to memory AT THE EARLIER location. This variable cannot be moved. Now, some optimizations are possible. -- If the address goes into a local variable only, the compiler can keep track of it's use, and verify correctness within this function. -- however, if the value gets stored into a global variable or passed to a function, then all bets are off. Any following function call or global pointer reference (after a function call), could use that pointer value. So, the summary is : DON'T TAKE THE ADDRESSES OF VARIABLES IF YOU WANT YOUR COMPILER TO DO OPTIMIZATIONS!!! --chris The more things change, the more they stay insane. ------------------------------------------------------------------------------- | Chris Quenelle | Smart Mailers -> cquenel@polyslo.CalPoly.EDU | | Computer Systems Lab | Dumb Mailers -> !ucbvax!voder!polyslo!cquenel | | Cal Poly State Univ. |-------------------------------------------------| | San Luis Obispo, CA 93407 | My computer can beat up your computer. - Karl | -------------------------------------------------------------------------------