www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - D_Version2 problem

reply Hoenir <mrmocool gmx.de> writes:
The D_Version2 version identifier doesn't work properly for me.
Tried compiling with dmd 1.039. D_Version2 is set even if I pass -v1 to it.

Is this a bug or am I doing something wrong?
Jan 18 2009
next sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Hoenir wrote:
 The D_Version2 version identifier doesn't work properly for me.
 Tried compiling with dmd 1.039. D_Version2 is set even if I pass -v1 to it.
 
 Is this a bug
Works for me, as this code demonstrates: ---------- import std.stdio; void main() { version (D_Version2) { writefln("D2"); } else { writefln("D1"); } } ----------
 or am I doing something wrong?
Possibly: - Inadvertently running the D2 compiler when you intended to run the D1 compiler - Misunderstanding how conditional compilation in D works .... Stewart.
Jan 18 2009
prev sibling next sibling parent reply Bill Baxter <wbaxter gmail.com> writes:
On Mon, Jan 19, 2009 at 6:28 AM, Hoenir <mrmocool gmx.de> wrote:
 The D_Version2 version identifier doesn't work properly for me.
 Tried compiling with dmd 1.039. D_Version2 is set even if I pass -v1 to it.

 Is this a bug or am I doing something wrong?
I just tried with DMD 1.037 and it worked fine. How are you using it? --bb
Jan 18 2009
parent Hoenir <mrmocool gmx.de> writes:
Bill Baxter schrieb:
 How are you using it?
 
Figured out what was wrong. I used const and stuff. Using a mixin now to bypass the problem.
Jan 18 2009
prev sibling parent reply Sergey Gromov <snake.scaly gmail.com> writes:
Sun, 18 Jan 2009 22:28:12 +0100, Hoenir wrote:

 The D_Version2 version identifier doesn't work properly for me.
 Tried compiling with dmd 1.039. D_Version2 is set even if I pass -v1 to it.
 
 Is this a bug or am I doing something wrong?
Works for me. It's hard to tell if you're doing something wrong until you post your test code. ----8<------ test.d version(D_Version2) { pragma(msg, "v2"); } else { pragma(msg, "v1"); } ----8<------
 dmd -c test.d
v1
Jan 18 2009
parent reply David Ferenczi <raggae ferenczi.net> writes:
== Quote from Sergey Gromov (snake.scaly gmail.com)'s article
 Sun, 18 Jan 2009 22:28:12 +0100, Hoenir wrote:
 The D_Version2 version identifier doesn't work properly for me.
 Tried compiling with dmd 1.039. D_Version2 is set even if I pass -v1 to it.

 Is this a bug or am I doing something wrong?
Works for me. It's hard to tell if you're doing something wrong until you post your test code. ----8<------ test.d version(D_Version2) { pragma(msg, "v2"); } else { pragma(msg, "v1"); } ----8<------
 dmd -c test.d
v1
The behaviour is a bit ambigous, since in compile time every version block gets interpreted! So you cannot put D2 only code in the version(D_Version2) {} block, if you want to compile your source with D1. I don't know if it's a bug or a feature. Regards, David
May 16 2009
next sibling parent David Ferenczi <raggae ferenczi.net> writes:
== Quote from David Ferenczi (raggae ferenczi.net)'s article
 == Quote from Sergey Gromov (snake.scaly gmail.com)'s article
 Sun, 18 Jan 2009 22:28:12 +0100, Hoenir wrote:
 The D_Version2 version identifier doesn't work properly for me.
 Tried compiling with dmd 1.039. D_Version2 is set even if I pass -v1 to it.

 Is this a bug or am I doing something wrong?
Works for me. It's hard to tell if you're doing something wrong until you post your test code. ----8<------ test.d version(D_Version2) { pragma(msg, "v2"); } else { pragma(msg, "v1"); } ----8<------
 dmd -c test.d
v1
The behaviour is a bit ambigous, since in compile time every version block gets
interpreted!
 So you cannot put D2 only code in the version(D_Version2) {} block, if you
want to
compile
 your source with D1.
 I don't know if it's a bug or a feature.
 Regards,
 David
Shoudl I file a bug report?
Jun 11 2009
prev sibling parent reply Robert Fraser <fraserofthenight gmail.com> writes:
David Ferenczi wrote:
 == Quote from Sergey Gromov (snake.scaly gmail.com)'s article
 Sun, 18 Jan 2009 22:28:12 +0100, Hoenir wrote:
 The D_Version2 version identifier doesn't work properly for me.
 Tried compiling with dmd 1.039. D_Version2 is set even if I pass -v1 to it.

 Is this a bug or am I doing something wrong?
Works for me. It's hard to tell if you're doing something wrong until you post your test code. ----8<------ test.d version(D_Version2) { pragma(msg, "v2"); } else { pragma(msg, "v1"); } ----8<------
 dmd -c test.d
v1
The behaviour is a bit ambigous, since in compile time every version block gets interpreted! So you cannot put D2 only code in the version(D_Version2) {} block, if you want to compile your source with D1. I don't know if it's a bug or a feature. Regards, David
This has been discussed many times over. It's a "feature" according to Walter, and there's some sense to it (since D code is supposed to be parseable without doing semantic analysis, and versions can require arbitrary ammounts of semantic analysis (like CTFE) to determine). If you want to have D2 code you need to use a mixin: version(D_Version2) { mixin("const(char)[] x;"); } else { char[] x; } Note that the -v1 switch reverts to the (rather arbitrary) D version 1.00, while new D features were being added through (I think) 1.014.
Jun 11 2009
parent David Ferenczi <raggae ferenczi.net> writes:
Robert Fraser wrote:

 David Ferenczi wrote:
 == Quote from Sergey Gromov (snake.scaly gmail.com)'s article
 Sun, 18 Jan 2009 22:28:12 +0100, Hoenir wrote:
 The D_Version2 version identifier doesn't work properly for me.
 Tried compiling with dmd 1.039. D_Version2 is set even if I pass -v1 to
 it.

 Is this a bug or am I doing something wrong?
Works for me. It's hard to tell if you're doing something wrong until you post your test code. ----8<------ test.d version(D_Version2) { pragma(msg, "v2"); } else { pragma(msg, "v1"); } ----8<------
 dmd -c test.d
v1
The behaviour is a bit ambigous, since in compile time every version block gets interpreted! So you cannot put D2 only code in the version(D_Version2) {} block, if you want to compile your source with D1. I don't know if it's a bug or a feature. Regards, David
This has been discussed many times over. It's a "feature" according to Walter, and there's some sense to it (since D code is supposed to be parseable without doing semantic analysis, and versions can require arbitrary ammounts of semantic analysis (like CTFE) to determine). If you want to have D2 code you need to use a mixin: version(D_Version2) { mixin("const(char)[] x;"); } else { char[] x; } Note that the -v1 switch reverts to the (rather arbitrary) D version 1.00, while new D features were being added through (I think) 1.014.
Many thanks for your answer. I should have missed this discussion. I still think, that it should be possible to skip the code blocks, which are behind not met version conditons. Maybe an extra compiler switch? Do I presume correctly that in case of using a mixin the literal won't be interpreted, and that's why it doesn't cause any problem?
Jun 11 2009