www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - CT usage only in executable

reply strtr <strtr sp.am> writes:
Not that the memory is really significant compared to the rest of my program,
but I have a few fairly large arrays I use only in compile time and I was
wondering why dmd still includes those in the executable (simple text search
dug them up).
Jul 14 2010
next sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
strtr:
 Not that the memory is really significant compared to the rest of my program,
 but I have a few fairly large arrays I use only in compile time and I was
 wondering why dmd still includes those in the executable (simple text search
 dug them up).
Are you able to create a smallish test case? Bye, bearophile
Jul 14 2010
parent reply strtr <strtr sp.am> writes:
== Quote from bearophile (bearophileHUGS lycos.com)'s article
 strtr:
 Not that the memory is really significant compared to the rest of my program,
 but I have a few fairly large arrays I use only in compile time and I was
 wondering why dmd still includes those in the executable (simple text search
 dug them up).
Are you able to create a smallish test case? Bye, bearophile
---- module main; const char[] CT_STRING = "int i=0;"; void main(){ mixin( CT_STRING ); } ---- The string can be found in the executable.
Jul 14 2010
next sibling parent reply strtr <strtr sp.am> writes:
== Quote from strtr (strtr sp.am)'s article
 == Quote from bearophile (bearophileHUGS lycos.com)'s article
 strtr:
 Not that the memory is really significant compared to the rest of my program,
 but I have a few fairly large arrays I use only in compile time and I was
 wondering why dmd still includes those in the executable (simple text search
 dug them up).
Are you able to create a smallish test case? Bye, bearophile
---- module main; const char[] CT_STRING = "int i=0;"; void main(){ mixin( CT_STRING ); } ---- The string can be found in the executable.
Too busy reading TDPL? ;) btw. how long until runtime mixins? :D
Jul 15 2010
parent bearophile <bearophileHUGS lycos.com> writes:
strtr:
 Too busy reading TDPL? ;)
I have not answered because my answer is not useful: I am sure that constant is present in the binary, you probably need LDC with Link-Time Optimization activated to remove them.
 btw. how long until runtime mixins? :D
D compiler contains an interpreter. It's not available at runtime mostly for design and ideological reasons, but in theory it's not hard to pull it out of the compiler and make it available at runtime too. Bye, bearophile
Jul 15 2010
prev sibling parent reply "Daniel Murphy" <yebblies nospamgmail.com> writes:
"strtr" <strtr sp.am> wrote in message news:i1lro6$307u$1 digitalmars.com...
 == Quote from bearophile (bearophileHUGS lycos.com)'s article
 strtr:
 Not that the memory is really significant compared to the rest of my 
 program,
 but I have a few fairly large arrays I use only in compile time and I 
 was
 wondering why dmd still includes those in the executable (simple text 
 search
 dug them up).
Are you able to create a smallish test case? Bye, bearophile
---- module main; const char[] CT_STRING = "int i=0;"; void main(){ mixin( CT_STRING ); } ---- The string can be found in the executable.
I think if you use enum instead of const/immutable the compiler is not meant to put them in the executable (it might anyway in some/all cases). eg. module main; enum CT_STRING = "int i=0;"; void main(){ mixin( CT_STRING ); }
Jul 16 2010
parent reply strtr <strtr sp.am> writes:
== Quote from Daniel Murphy (yebblies nospamgmail.com)'s article
 I think if you use enum instead of const/immutable the compiler is not meant
 to put them in the executable (it might anyway in some/all cases).
 eg.
 module main;
 enum CT_STRING = "int i=0;";
 void main(){
 mixin( CT_STRING );
 }
I'm using D1. Should I report this as a bug?
Jul 16 2010
parent reply "Daniel Murphy" <yebblies nospamgmail.com> writes:
"strtr" <strtr sp.am> wrote in message news:i1ql53$306c$1 digitalmars.com...
 == Quote from Daniel Murphy (yebblies nospamgmail.com)'s article
 I think if you use enum instead of const/immutable the compiler is not 
 meant
 to put them in the executable (it might anyway in some/all cases).
 eg.
 module main;
 enum CT_STRING = "int i=0;";
 void main(){
 mixin( CT_STRING );
 }
I'm using D1. Should I report this as a bug?
Sorry, I don't have D1 installed. Can you use enum to declare manifest constants in D1 or is it a D2 thing? If the string is left in the executable from const char[] CT_STRING = "blah blah"; void main () {} then I think this is a bug/enhancement for the linker.
Jul 16 2010
parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Daniel Murphy <yebblies nospamgmail.com> wrote:

 Sorry, I don't have D1 installed.  Can you use enum to declare manifest
 constants in D1 or is it a D2 thing?
It's a D2 thing. I believe the D1 way to do it is with static const.
 If the string is left in the executable from

 const char[] CT_STRING = "blah blah";
 void main () {}

 then I think this is a bug/enhancement for the linker.
Enhancement, I'd say. And yes, DMD does that. It's the reason for the enum manifest constants in D2. -- Simen
Jul 16 2010
prev sibling parent reply torhu <no spam.invalid> writes:
On 15.07.2010 02:29, strtr wrote:
 Not that the memory is really significant compared to the rest of my program,
 but I have a few fairly large arrays I use only in compile time and I was
 wondering why dmd still includes those in the executable (simple text search
 dug them up).
As a workaround you could try putting those arrays in a separate module which you don't link into your executable. If you use a build tool like xfbuild, you can exclude files with the -X switch. CTFE would still work.
Jul 17 2010
parent strtr <strtr sp.am> writes:
== Quote from torhu (no spam.invalid)'s article
 On 15.07.2010 02:29, strtr wrote:
 Not that the memory is really significant compared to the rest of my program,
 but I have a few fairly large arrays I use only in compile time and I was
 wondering why dmd still includes those in the executable (simple text search
 dug them up).
As a workaround you could try putting those arrays in a separate module which you don't link into your executable. If you use a build tool like xfbuild, you can exclude files with the -X switch. CTFE would still work.
Thanks, I'll try that if dmd will not do this as well before my program is finished :)
Jul 17 2010