Re: C++ Frequently Questioned Answers
Jerry Coffin wrote:
In article <4737510D.1050600@erdani.org>, SeeWebsiteForEmail@erdani.org
says...
[ ... ]
I have another challenge, which is more interesting and arguably useful:
computing efficient logarithm tables during compilation.
See http://www.icsi.berkeley.edu/pubs/techreports/TR-07-002.pdf for a
description of the problem and a solution based on runtime code generation.
It looks to me like runtime code generation is probably more efficient
for this case. According to the paper, it's almost as fast to generate
the data on the fly as it is to read it from main memory. That being the
case, it's almost _certainly_ faster to generate it on the fly than the
read it in from disk, which is what would be needed if you generated it
at compile-time.
However, programmers in general and C++ programmers in particular are
very keen on only using the C++ compiler (to wit, many template and
preprocessor libraries and their uses). I'm not sure exactly why, but
there is an extraordinary appeal of staying within the language. In
fact, I'd love to gather opinions on why that's the case.
But say we are willing to write Perl scripts and edit makefiles (and
honestly I don't mind getting my hands greased). But there are more
examples, for which it is increasingly hard to generate code with
external tools. For example, given an interface X, generate a class that
implements all of X's virtual functions to return the default value of
their result type. Or implement it to throw exceptions saying "Member
function X::Y failed". Or implement it to marshal the call to a
different computer. For such problems, the prospect of using an outside
code generator becomes onerous as we're starting to talk about a parser
that looks at X and understands its structure.
(Oh, and as far as reading stuff from disk goes - I think what you say
is true but irrelevant. Programs of the kind that needs log tables will
run for hours at least, so load time is not a factor.)
Andrei
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]