From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@cse.psu.edu From: "Thomas Bushnell, BSG" Message-ID: <87u1s2y1uu.fsf@becket.becket.net> Content-Type: text/plain; charset=us-ascii References: , <3C7CFAFE.4996DA2A@research.bell-labs.com> Subject: Re: [9fans] plan or side effect Date: Thu, 28 Feb 2002 09:58:14 +0000 Topicbox-Message-UUID: 5aea0510-eaca-11e9-9e20-41e7f4b1d025 seanq@research.bell-labs.com (Sean Quinlan) writes: > The compiler will registerise > such variables within a function even though it is possible > that the variable is aliased via a pointer. Well, that's a bug, certainly. GCC does not make such assumptions. More specifically, the canonical copy of a global is stored in memory, and all function calls are assumed to dirty all of memory. As a result, a global variable can be registerized, but after any function call, it must be assumed that the value has changed, and the register copy must therefore by synced before and after the function call. In the presence of concurrence, even this is not sufficient, because a different thread could clobber the value. However, C does not guarantee synchronization in this case unless the variable is marked "volatile". (And if it is so marked, GCC doesn't do any registerization at all.) Thomas