🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #5434

Taking the address of local variables

#5434
From: Suspended in Gaffa
Date: Sun, 20 Nov 1988 21:58
37 lines
2062 bytes
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  |
-------------------------------------------------------------------------------
Technical Details
Message-ID: <6037@polyslo.CalPoly.EDU>
Path: arc1-ca.pugleaf.net!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
References: <6472@june.cs.washington.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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