Date: Tue, 5 Mar 2002 18:24:14 -0800 From: Dan Grillo <Dan_Grillo@grillo.net> To: freebsd-chat@FreeBSD.ORG Subject: Re: C vs C++ Message-ID: <200203060224.SAA84674@grillo.net> References: <3C8529DA.FA8ABCE@mindspring.com> <20020305164151.T5854-100000@alpha.yumyumyum.org> <15493.24457.986109.726909@caddis.yogotech.com> <3C8573B2.35144B17@attbi.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <foo.h> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200203060224.SAA84674>