This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: pure and const functions




--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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]