From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2038 invoked by alias); 3 Jan 2008 01:22:05 -0000 Received: (qmail 1982 invoked by uid 22791); 3 Jan 2008 01:22:01 -0000 X-Spam-Check-By: sourceware.org Received: from Unknown (HELO devsrv.otsc.com.cn) (203.187.177.119) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 03 Jan 2008 01:18:19 +0000 Received: from [127.0.0.1] (longhaitao [192.168.0.7]) by devsrv.otsc.com.cn (Postfix) with ESMTP id 843E0465F64; Thu, 3 Jan 2008 09:14:38 +0800 (CST) Message-ID: <477C37E0.1060006@otsc.com.cn> Date: Fri, 04 Jan 2008 14:38:00 -0000 From: =?GB2312?B?wfq6o8zO?= User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: John Love-Jensen , gcc-help@gcc.gnu.org Subject: Re: a question about code optimization References: In-Reply-To: Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2008-01/txt/msg00029.txt.bz2 John Love-Jensen дµÀ: > Hi, > > In this particular example, the size() method is inline, so the compiler > injects it locally into the code, and hence the compiler is aware if size() > changes some global variable or not. > > If size() were non-inline, it would be a "black box" to the optimizer, so in > that case your analysis is correct. > > --Eljay yes, size() function is inline, but consider this situation: we can call some non-inline functions in inline function,i.e, void foo_non_inline(); inline int foo_inline() { /*...*/ foo_non_inline(); /*...*/ } obviously we are not sure that the global variabls are changed or not in foo_non_inline(); So my questions is: is gcc *smart* enough that she can determine when to do the optimization? > > On 12/21/07 11:41 PM, "Áúº£ÌÎ" wrote: > >> ---------code----------- >> vector a; >> /*do somthing*/ >> for(int i = 0; i> /* do something*/ >> } >> --------code end-------- >> >> my question is: >> is it possible that the compiler will transform the code to this: >> >> int __tmp = a.size(); >> for(int i = 0; i < __tmp; i++) { >> /*do something*/ >> } >> >> i think it is impoossible,because in size() function, the programmer >> can change some global variables, so the compiler could not do that. >> >> if gcc can, could you tell me how? >> >> i am sorry in advance because i am not familiar with the code optimization. >> so i do not know how to search the gcc manual and gcc internal manual to find >> answer.could anyone tell me how to find this in the manual£¿or at least give >> some keywords? >