🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3600

Re: constant-expression extension

#3600
From: James Kanze US/ESC 60/3/141 #407...
Date: Wed, 06 Mar 1996 17:43
51 lines
3298 bytes
In article <4hh34b$21r@ugress.uib.no> boukanov@kvark.fi.uib.no (Igor
Boukanov) writes:

|> J. Kanze (kanze@gabi-soft.fr) wrote:
|> > That it would be nice, but that there are two very big problems:

|> > 1. It would basically require a complete C++ interpreter in the
|> > compiler, and

|> But in almost all cases such interpreter is already present in C++ 
|> compilers! Because of cause all such const look expressions are correct 
|> C++ expressions so every C++ compiler has to generate a code that will 
|> evaluate them at run time and if forget about the crosscompilation case 
|> I think instead of putting the code to object file compiler can just execute 
|> it...

Generating code and interpreting it are two different things.  For
example, the code generator only knows about the current scope (stack
frame); the compiler typically has no mechanism for maintaining the
image of multiple stack frames (needed is it is to evaluate a
function) internall.

|> > 2. It would make the notion of constant expression somewhat
|> > implementation dependant.  Suppose my compiler implements the function
|> > sin as an inline invocation of a compiler built-in.  Can I then use sin
|> > in a constant expression?

|> Consider, for example, next:
|> const double x = 1.0 / (very small number); 
|> And of cause, the result will depend on exact representation of double... 

Agreed.  That is why the above is not a constant expression, according
to the draft standard.  Think about the case of a cross-compiler: it
would be very unintuitive if `1.0 / (very small number)' gave
different results than assigning 1.0 to a double variable, then
dividing the double variable by `(a very small number)'.  A
(cross-)compiler is not required to emulate the floating point
arithmetic of the target machine.

--
James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils, itudes et rialisations en logiciel orienti objet --
                -- A la recherche d'une activiti dans une region francophone
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]
Technical Details
Message-ID: <9603061619.AA10444@lts.sel.alcatel.de>
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
References: <4h775a$m4s@ugress.uib.no> <KANZE.96Mar4120725@gabi.gabi-soft.fr> <4hh34b$21r@ugress.uib.no>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
From: James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de>
Newsgroups: comp.std.c++
Subject: Re: constant-expression extension
Date: 06 Mar 1996 09:43:18 PST
Organization: -
Approved: austern@isolde.mti.sgi.com
Message-ID: <9603061619.AA10444@lts.sel.alcatel.de>
References: <4h775a$m4s@ugress.uib.no> <KANZE.96Mar4120725@gabi.gabi-soft.fr> <4hh34b$21r@ugress.uib.no>
NNTP-Posting-Host: isolde.mti.sgi.com
X-Original-Date: Wed, 6 Mar 96 17:19:38 +0100
In-Reply-To: boukanov@kvark.fi.uib.no's message of 05 Mar 1996 09:44:14 PST
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBVAwUBMT3OzEy4NqrwXLNJAQGwpgH/TYx1AwN2trtDktdsVqXbfb5Smm10QHJu
 vC+yjSIJpCDnqjy0Hn3iVuGo0eYerx5f6Hf/es4JYMl22TbZ+sEFEg==
 =Knaj
Originator: austern@isolde.mti.sgi.com