This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: pure and const functions
- From: Mark Mitchell <mark at codesourcery dot com>
- To: Chris Lattner <sabre at nondot dot org>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Fri, 26 Apr 2002 11:57:31 -0700
- Subject: RE: pure and const functions
- References: <Pine.LNX.4.30.0204261145220.2837-100000@nondot.org>
--On Friday, April 26, 2002 11:50:07 AM -0500 Chris Lattner
<sabre@nondot.org> wrote:
>
>> 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.
Actually, C does not guarantee that negative values wrap around to
positive values.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com