From -7728577387036781133
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,ec4b60e80d49f4fe
X-Google-Attributes: gidf78e5,public
From: Valentin Bonnard <bonnardv@pratique.fr>
Subject: Re: Constant expression (Was: Re: Loop invariance)
Date: 1998/08/06
Message-ID: <35CA360C.3EF7@pratique.fr>#1/1
X-Deja-AN: 378667718
X-NNTP-Posting-Host: cyber31-9.paris.imaginet.fr
Content-Transfer-Encoding: 7bit
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <35C1FD0B.6EF2@bean.jpl.nasa.gov> <35C67E63.69530B1C@ix.netcom.com> <6q7q3c$omn$1@nnrp1.dejanews.com> <35C8A8B3.77BC@pratique.fr> <35C8C39D.41C6@wizard.net>
To: James Kuyper <kuyper@wizard.net>
X-UID: 0000000001
X-Status: $$$T
Content-Type: text/plain; charset=us-ascii
Organization: Ecole Normale Superieure, Paris, France
Mime-Version: 1.0
Reply-To: bonnardv@pratique.fr
Newsgroups: comp.std.c++
Originator: clamage@taumet

James Kuyper <kuyper@wizard.net> writes:

> Valentin Bonnard wrote:
> > 
> > AllanW@my-dejanews.com wrote:
> > 
> > > Five years ago, I would write code like this:
> > >     const int days_in_Q1 = 91; // 31+28+31;
> > > instead of:
> > >     const int days_in_Q1 = 31+28+31;
> > > because I knew that some compilers would do the addition at runtime.
> > 
> > A conforming C++ compiler is required to compute the sum.
> > Computation of integral constant expressions can't be
> > defered to runtime. But there is no such requirement in
> > the following example:
> > 
> > const float sum = 2. + 4.;
> 
> Citations please? How could a conforming program tell? 

It can't. Explanation follows.

> The standard does
> a very precise definition of tranlation phases, but seldom explicitly
> distiguishes run-time from compile-time.

The principle of the least punishement: an implementor doesn't 
make extra efforts (takes extra work/ressources) to punish 
his customers. For example, if I hear someone saying that 
'identifiers with the letter "j" in them should be avoided because 
a compiler could slow down accesses to such identifiers', I will 
answer that it's wrong under the least punishement principle: 
it would require extra work to add this slowdown (the compiler 
would test if the letter j is used, then punish the programmer 
with the slowdown).

Does this explanation satisfies you ?

-- 

Valentin Bonnard                mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://pages.pratique.fr/~bonnardv/


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




