CTFE bug causes null check to pass on null pointers (Issue 7602)

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Mar 21 08:33:46 PDT 2012


On Wed, Mar 21, 2012 at 10:55:05AM +0100, David Nadlinger wrote:
> On Wednesday, 21 March 2012 at 09:51:43 UTC, Jens Mueller wrote:
> >Interesting. How do I make use of this?
> >
> >[…]
> >
> >What's the trick to use memory allocated in a CTFE. Say e.g. I want
> >to build a tree at compile time using CTFE.
> 
> You can't do that right now (i.e. converting CTFE-allocated memory to
> initializers for run-time values), but it enables you to use classes,
> etc. _during_ CTFE.
[...]

Actually you can... though it requires hacks using string mixins.

Basically, you create the structure in CTFE, then walk the structure and
construct a string containing declarations of the form:

	"struct node __node_1234 = { value1, value2, ... };"

then use a string mixin to instantiate them. This will create the tree
nodes as module globals, so they are compiled into the object file. They
therefore also have runtime addresses, so the root of the tree can be
assigned into a runtime tree pointer, for example.


T

-- 
Let X be the set not defined by this sentence...


More information about the Digitalmars-d mailing list