From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13243 invoked by alias); 26 Apr 2002 16:53:20 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 13226 invoked from network); 26 Apr 2002 16:53:15 -0000 Received: from unknown (HELO nondot.org) (64.5.103.85) by sources.redhat.com with SMTP; 26 Apr 2002 16:53:15 -0000 Received: by nondot.org (Postfix, from userid 501) id D631E11883; Fri, 26 Apr 2002 11:50:07 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by nondot.org (Postfix) with ESMTP id D1F201183E for ; Fri, 26 Apr 2002 11:50:07 -0500 (CDT) Date: Fri, 26 Apr 2002 10:17:00 -0000 From: Chris Lattner To: Subject: RE: pure and const functions Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-SW-Source: 2002-04/txt/msg01425.txt.bz2 > int fib(int n) { > if (n==0 || n==1) return n; > return fib(n-1) + fib(n-2); > } > According to the definitions given above, this function is const, > but not total, because it does not return for negative n. While this is true in a practical sense, given infinite resources, this is certainly not the case. Assuming you had a whole lot of stack space and bunch of time, the negative values for 'n' would wrap around to positive values. Eventually it would get to 1 and terminate. As this is the case, for this example... int double_or_nothing (int n) { fib(n); return 2*n; } ... it should be optimizable to: int double_or_nothing (int n) { return 2*n; } ...because on an ideal, theoretical, machine, they results are exactly the same. IOW: we don't try to predict stack overflow in other cases, so why should we have to worry about that possibility here? There may be other cases where functions are "partial", can you give another example? -Chris http://www.nondot.org/~sabre/os/ http://www.nondot.org/~sabre/Projects/