From: Tim Hollebeek <tim@hollebeek.com>
To: Chris Lattner <sabre@nondot.org>
Cc: gcc@gcc.gnu.org
Subject: Re: pure and const functions
Date: Fri, 26 Apr 2002 10:26:00 -0000 [thread overview]
Message-ID: <20020426132525.A30261@pcp736370pcs.reston01.va.comcast.net> (raw)
In-Reply-To: <Pine.LNX.4.30.0204261145220.2837-100000@nondot.org>
On Fri, Apr 26, 2002 at 11:50:07AM -0500, Chris Lattner 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.
Actually, it's signed, so we get undefined behavior instead. This
*really* muddies the waters, since the compiler need only preserve the
behavior of programs that don't invoke undefined behavior.
> There may be other cases where functions are "partial", can you give
> another example?
There are similar obvious trivial examples:
int hang_unless_positive(int n) /* a const function */ {
if (n <= 0) {
while (1) {
}
}
return n;
}
void do_nothing(int n) {
hang_unless_positive(n) + hang_unless_positive(-n);
launch_preemptive_nuclear_strike_on_arkansas();
}
next prev parent reply other threads:[~2002-04-26 17:22 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-26 10:17 Chris Lattner
2002-04-26 10:21 ` Kris Warkentin
2002-04-26 10:30 ` Chris Lattner
2002-04-26 10:34 ` Magnus Fromreide
2002-04-26 10:35 ` Chris Lattner
2002-04-26 10:59 ` Magnus Fromreide
2002-04-26 11:03 ` Chris Lattner
2002-04-26 11:27 ` Magnus Fromreide
2002-04-26 12:49 ` Russ Allbery
2002-04-26 10:36 ` Kris Warkentin
2002-04-26 10:46 ` Chris Lattner
2002-04-26 10:26 ` Tim Hollebeek [this message]
2002-04-26 10:30 ` Chris Lattner
2002-04-26 10:56 ` Zack Weinberg
2002-04-26 11:01 ` Chris Lattner
2002-08-30 23:02 ` Zack Weinberg
2002-04-26 10:56 ` Tony Finch
2002-04-26 12:11 ` Mark Mitchell
-- strict thread matches above, loose matches on Subject: below --
2002-04-29 17:25 John Wehle
2002-04-29 9:29 Robert Dewar
2002-04-29 9:34 ` Chris Lattner
2002-04-29 8:30 Robert Dewar
2002-04-29 8:57 ` Chris Lattner
2002-04-29 8:30 Chris Lattner
2002-04-29 9:23 ` Daniel Berlin
2002-04-29 9:52 ` Chris Lattner
2002-04-29 9:58 ` Mark Dettinger
2002-04-29 5:18 Robert Dewar
2002-04-29 5:44 ` Mark Dettinger
2002-04-29 3:59 Mark Dettinger
2002-04-26 5:16 Mark Dettinger
2002-04-26 11:20 ` Joseph S. Myers
2002-04-26 12:59 ` Jakub Jelinek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020426132525.A30261@pcp736370pcs.reston01.va.comcast.net \
--to=tim@hollebeek.com \
--cc=gcc@gcc.gnu.org \
--cc=sabre@nondot.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).