Re: Executing code at compilation time

Ray <bear@sonic.net>
Mon, 22 Mar 2010 11:24:27 -0700

          From comp.compilers

Related articles
[11 earlier articles]
Re: Executing code at compilation time pat@jantar.org (Patryk Zadarnowski) (2010-03-17)
Re: Executing code at compilation time gah@ugcs.caltech.edu (glen herrmannsfeldt) (2010-03-17)
Re: Executing code at compilation time bear@sonic.net (Ray) (2010-03-19)
Re: Executing code at compilation time bear@sonic.net (Ray) (2010-03-19)
Re: Executing code at compilation time bobduff@shell01.TheWorld.com (Robert A Duff) (2010-03-21)
Re: Executing code at compilation time torbenm@diku.dk (2010-03-22)
Re: Executing code at compilation time bear@sonic.net (Ray) (2010-03-22)
Re: Executing code at compilation time gah@ugcs.caltech.edu (glen herrmannsfeldt) (2010-03-23)
Re: Executing code at compilation time martin@gkc.org.uk (Martin Ward) (2010-03-26)
| List of all articles for this month |

From: Ray <bear@sonic.net>
Newsgroups: comp.compilers
Date: Mon, 22 Mar 2010 11:24:27 -0700
Organization: Doubtful
References: 10-03-038 10-03-050 10-03-056 10-03-065
Keywords: optimize
Posted-Date: 22 Mar 2010 21:18:51 EDT

Robert A Duff wrote:


> Could you please post an example of what you mean?
>
> I've certainly seen cases where an infinite loop is
> desired, but I'm not sure that answers your question.
>
> - Bob
> [I expect he means things like sum i=1 to infinity of 2^(-i) which we
> know analytically is 1. -John]


Yes, John got it right. If we have C code which says,


double addend = 0.5;
double sum = 0.0;
while (1){
      sum += addend;
      addend *= 0.5;
}


Then the programmer is a maniac.


Regardless of the programmer's problems, if the compiler uses
infinite-sum laws and "unrolls" it generating the same object code
that it would for


double addend = 0.00;
double sum = 1.00;


This loop has no side effects (including doing no I/O). Therefore it
does nothing useful unless/until it completes. And we can tell what
the final values will be "when" it completes; can we skip the loop?




Is that an optimization or a semantic violation?


                                                Bear



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.