ponce

Jonathan M Davis jmdavisProg at gmx.com
Tue Nov 9 17:30:53 PST 2010


On Tuesday, November 09, 2010 16:24:30 div0 wrote:
> On 10/11/2010 00:16, Jonathan M Davis wrote:
> > On Tuesday, November 09, 2010 13:49:12 bearophile wrote:
> >> Jonathan M Davis:
> >>> it would be possible to make it so that any objects allocated with
> >>> new during CTFE would be in the dynamic heap during runtime.
> >> 
> >> This is possible, but it doesn't seem what you usually desire when you
> >> allocate an object at compile time.
> > 
> > Why not? CTFE stuff should either disappear in the binary, because it's
> > not needed anymore, or it should be the same as if it were created at
> > runtime. CTFE is a great opportunity to create more complicated stuff at
> > cheaper cost (since the calculations are done at compile time instead of
> > runtime), and more importantly, have compile-time constants which are
> > more complex. It's also a great way to generate code. But I don't see
> > why you'd want statically-created objects to be treated differently once
> > the program is running.
> > 
> > - Jonathan M Davis
> 
> No, that's completely wrong.
> 
> CTFE should result in constant initialisation values, eg stuff in the
> .exes read only data segment.
> 
> CTFE is the same as:
> 
> immutable string _someString = "hello world!";
> 
> Expect that it's:
> 
> immutable string _someString = reallyComplicatedCTFEfunction();

There are plenty of cases where CTFE is used to create constants, but there are 
also plenty of places where it can create non-constants - such as setting the 
initial value for a member variable. Personally, I don't want to have to worry 
about where in memory an object lives. Constants can - to some extent - be 
treated as special, but CTFE is _not_ only for generating constants.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list