Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750853AbVKJN1F (ORCPT ); Thu, 10 Nov 2005 08:27:05 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1750852AbVKJN1E (ORCPT ); Thu, 10 Nov 2005 08:27:04 -0500 Received: from moraine.clusterfs.com ([66.96.26.190]:36274 "EHLO moraine.clusterfs.com") by vger.kernel.org with ESMTP id S1750853AbVKJN1D (ORCPT ); Thu, 10 Nov 2005 08:27:03 -0500 From: Nikita Danilov MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <17267.19126.260133.903822@gargle.gargle.HOWL> Date: Thu, 10 Nov 2005 16:27:18 +0300 To: "J.A. Magallon" Cc: linux-kernel@vger.kernel.org Subject: Re: typedefs and structs Newsgroups: gmane.linux.kernel In-Reply-To: <20051110091517.2e9db750@werewolf.auna.net> References: <20051107204136.GG19593@austin.ibm.com> <1131412273.14381.142.camel@localhost.localdomain> <20051108232327.GA19593@austin.ibm.com> <20051109003048.GK19593@austin.ibm.com> <20051109004808.GM19593@austin.ibm.com> <19255C96-8B64-4615-A3A7-9E5A850DE398@mac.com> <20051109111640.757f399a@werewolf.auna.net> <20051109192028.GP19593@austin.ibm.com> <20051110091517.2e9db750@werewolf.auna.net> X-Mailer: VM 7.17 under 21.5 (patch 17) "chayote" (+CVS-20040321) XEmacs Lucid Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1346 Lines: 45 J.A. Magallon writes: [...] > > > > However, if the code is as follows: > > void foo (void) { > > int myvar = 0; > > printf("%d\n", myvar); > > bar(&myvar); > > printf("%d\n", myvar); > > } > > If bar is declared in _another_ file as > > void bar (const int * var); > > then I think the compiler can validly cache the value of 'myvar' for the > > second printf without re-reading it. Correct/incorrect? > > > > Nope. You can't trust bar() not doing something like > > bar(const int* local_var) > { > ... use local_var as ro... > extern int myvar; > myvar = 7; > } > > For the compiler to do that, you must tag bar() with attribute(pure). extern declaration in your version of bar() cannot refer to the automatic variable myvar in foo(). > > -- > J.A. Magallon \ Software is like sex: > werewolf!able!es \ It's better when it's free > Mandriva Linux release 2006.1 (Cooker) for i586 > Linux 2.6.14-jam1 (gcc 4.0.2 (4.0.2-1mdk for Mandriva Linux release 2006.1)) Nikita. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/