From owner-freebsd-chat Tue Mar 5 18:24:22 2002 Delivered-To: freebsd-chat@freebsd.org Received: from grillo.net (adsl-216-103-84-67.dsl.snfc21.pacbell.net [216.103.84.67]) by hub.freebsd.org (Postfix) with ESMTP id D3E5B37B402 for ; Tue, 5 Mar 2002 18:24:15 -0800 (PST) Received: (from grio@localhost) by grillo.net (8.9.3/8.9.3) id SAA84674; Tue, 5 Mar 2002 18:24:15 -0800 (PST) (envelope-from grio) From: Dan Grillo Message-Id: <200203060224.SAA84674@grillo.net> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Organization: President, Grillo Networking, Inc. To: freebsd-chat@FreeBSD.ORG Subject: Re: C vs C++ References: <3C8529DA.FA8ABCE@mindspring.com> <20020305164151.T5854-100000@alpha.yumyumyum.org> <15493.24457.986109.726909@caddis.yogotech.com> <3C8573B2.35144B17@attbi.com> Date: Tue, 5 Mar 2002 18:24:14 -0800 Versions: dmail (bsd44) 2.4/makemail 2.9b Sender: owner-freebsd-chat@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org FreeBSDer's, Here's a little C++ riddle... --------------------------------------------------------- C++ riddle by Erik Kay Looking at the following piece of C++ code, what is the maximum number of *direct* function calls (in other words, where the stack depth is 1 deeper than this function) that this function could make? As a second question, what is the *minimum* number of direct function calls that this function must make (assuming no exceptions are thrown). For your answers, you should enumerate what those function calls are. You can make the following assumptions: cpp is only used to process the #include (in other words, no #define silliness) none of the code referenced uses inlined functions the line "C c = new C..." is not a typo there are no typedefs don't count compiler optimizations for the minimum (count unnecessary function calls that a good optimizer might remove) #include C foo() { A a(bar()); B b(baz(), quux()); C c = new C(a + b + a); return c; } Hints: Don't forget implicit functions, even on the minimum side of the problem. On the maximum side, the maximum can get very gross - for example, what if bar() returned an int, but there's no constructor for A that takes an int. Could you come up with code where that could compile? What about temporary objects? --------------------------------------------------------- I'll post the answers in a few days. --Dan -- Dan Grillo dan@grillo.net (650) 917-0685 fax (775) 248-7762 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-chat" in the body of the message