CTFE attribute
Manu
turkeyman at gmail.com
Sat Jan 28 07:13:03 PST 2012
On 28 January 2012 17:03, Robert Clipsham <robert at octarineparrot.com> wrote:
> On 28/01/2012 14:50, Manu wrote:
>
>> This has come up lots of times before.. I just wanted to effectively +1
>> this request.
>>
>> I have some templates, and some reasonably complex functions I use
>> strictly via CTFE to produce enums and evaluate conditions within the
>> templates.
>> When I build my code, I notice that the CTFE functions, which are never
>> referenced in any runtime code, are still present in the object file.
>> Additionally, one of these functions requires I import std.string, which
>> is only used in CTFE code, and is otherwise a pointless import.
>>
>> I'd certainly like to be able to mark these functions CTFE to be sure no
>> runtime code will ever be generated for them, and also, what can I do
>> about CTFE imports? I don't want that import in my binary...
>>
>
> There are a couple of things you can do. The first is to make the imports
> function local, the second is:
>
> http://www.digitalmars.com/d/**archives/digitalmars/D/**
> Incremental_compilation_with_**DMD_96138.html#N96337<http://www.digitalmars.com/d/archives/digitalmars/D/Incremental_compilation_with_DMD_96138.html#N96337>
>
> You'll notice that thread mentions a pragma(ctfe) patch for DMD, that's
> another option, though would require a patched compiler. I can't seem to
> find a link to that patch, a bit of googling should help though.
>
> Another idea I've just had:
>
> T myComplexFuntion()
> {
> if (__ctfe)
> {
> // Implement here
> }
> else
> {
> assert(0);
> }
> }
>
> This should allow the function to be inlined to assert(0); if it's called
> at runtime, so while it will still exist in the binary, it won't introduce
> lots of additional bloat.
Sweet, I'll do that for now.
You mean static if() right?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120128/475ec5a5/attachment.html>
More information about the Digitalmars-d
mailing list