Re: Global variables read at compile time?

2014-05-06 Thread Suliman via Digitalmars-d-learn
I am tying to hardcode name of config file name. Then I would read and parse it.

Re: Global variables read at compile time?

2014-05-06 Thread Ali Çehreli via Digitalmars-d-learn
On 05/06/2014 07:40 AM, Suliman wrote: Thanks! But is there any other solution? I am thinking that I am trying to specify config name by wrong way... Sorry, I don't understand what exactly you are trying to do. :( Is config file a compile-time concept? Do you want to read it at compile time?

Re: Global variables read at compile time?

2014-05-06 Thread Suliman via Digitalmars-d-learn
Thanks! But is there any other solution? I am thinking that I am trying to specify config name by wrong way...

Re: Global variables read at compile time?

2014-05-06 Thread Ali Çehreli via Digitalmars-d-learn
On 05/06/2014 03:16 AM, Suliman wrote: > When I had create instance of class in main, and create confvarible > above it all worked, but when I had moved it's in module I got error. There is module 'static this()' for such runtime initialization: Config config; static this() { config = new

Re: Global variables read at compile time?

2014-05-06 Thread Suliman via Digitalmars-d-learn
I have got same error. I need to pass in instance of class constant, but got error "Error: static variable cannot be read at compile" http://www.everfall.com/paste/id.php?1mc9mb9cxyie When I had create instance of class in main, and create confvarible above it all worked, but when I had move

Re: Global variables read at compile time?

2012-08-15 Thread Leandro Motta Barros
Another option is to use "module constructors", as shown below. (But somehow this all looks a bit fishy for me...) LMB import std.stdio; string a = "a"; string b; static this() { b = a; } void main() { writeln(b); } On Wed, Aug 15, 2012 at 11:03 AM, d_follower wrote: > On Wednes

Re: Global variables read at compile time?

2012-08-15 Thread Ali Çehreli
On 08/15/2012 06:55 AM, d_follower wrote: On Wednesday, 15 August 2012 at 13:41:10 UTC, RommelVR wrote: Make a an enum, const or otherwise immutable. I don't think you understood the question. I thought RommelVR did understand the question. Try this: import std.stdio; enum a = "a"; string

Re: Global variables read at compile time?

2012-08-15 Thread Justin Whear
On Wed, 15 Aug 2012 15:36:24 +0200, Stefan wrote: > Hi there, I'm having trouble getting the following code to compile: > > import std.stdio; > > string a = "a"; > string b = a; > > void main() > { > writeln(b); > } > > DMD spits out the error "test.d(4): Error: variable a cannot be read

Re: Global variables read at compile time?

2012-08-15 Thread Andrej Mitrovic
On 8/15/12, d_follower wrote: > I don't really know why, but it seems that you can only > initialize globals with constants. That's what the static constructor is for: http://dlang.org/class.html#StaticConstructor http://dlang.org/class.html#SharedStaticConstructor

Re: Global variables read at compile time?

2012-08-15 Thread Jesse Phillips
On Wednesday, 15 August 2012 at 13:36:26 UTC, Stefan wrote: Hi there, I'm having trouble getting the following code to compile: import std.stdio; string a = "a"; string b = a; void main() { writeln(b); } DMD spits out the error "test.d(4): Error: variable a cannot be read at compile tim

Re: Global variables read at compile time?

2012-08-15 Thread d_follower
On Wednesday, 15 August 2012 at 13:36:26 UTC, Stefan wrote: Hi there, I'm having trouble getting the following code to compile: import std.stdio; string a = "a"; string b = a;// line 4 void main() { writeln(b); // line 8 } DMD spits out the error "test.d(4): Error: variable

Re: Global variables read at compile time?

2012-08-15 Thread d_follower
On Wednesday, 15 August 2012 at 13:41:10 UTC, RommelVR wrote: Make a an enum, const or otherwise immutable. I don't think you understood the question.

Re: Global variables read at compile time?

2012-08-15 Thread RommelVR
On Wednesday, 15 August 2012 at 13:36:26 UTC, Stefan wrote: Hi there, I'm having trouble getting the following code to compile: import std.stdio; string a = "a"; string b = a; void main() { writeln(b); } DMD spits out the error "test.d(4): Error: variable a cannot be read at compile tim

Global variables read at compile time?

2012-08-15 Thread Stefan
Hi there, I'm having trouble getting the following code to compile: import std.stdio; string a = "a"; string b = a; void main() { writeln(b); } DMD spits out the error "test.d(4): Error: variable a cannot be read at compile time". Is there any way to tell the compiler I want b evaluated