www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - What is the point of D_Version2

reply Derek Parnell <derek psych.ward> writes:
Okay, I just don't get it.

This code below doesn't compile in V1 dmd.

version(D_Version2)
{
    alias const(wchar)[] wstring;
    alias const(dchar)[] dstring;
}
else
{
    alias char[] string;
    alias wchar[] wstring;
    alias dchar[] dstring;
}


I can understand why - because the first two alias declarations have
invalid V1 syntax - but doesn't that make the whole D_Version2 thing
pointless?

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell
Sep 02 2007
next sibling parent reply Derek Parnell <derek psych.ward> writes:
On Sun, 2 Sep 2007 22:50:32 +1000, Derek Parnell wrote:

P.S. I finally got Bud to compile using V2 after about a thousand tiny
changes and now I want to tweak so I can also compile the same source in
V1. 

Needless to say, but there will be a slight delay in the next Bud release
until I sort out this next bloody irritation.

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell
Sep 02 2007
parent Bill Baxter <dnewsgroup billbaxter.com> writes:
Derek Parnell wrote:
 On Sun, 2 Sep 2007 22:50:32 +1000, Derek Parnell wrote:
 
 P.S. I finally got Bud to compile using V2 after about a thousand tiny
 changes and now I want to tweak so I can also compile the same source in
 V1. 
 
 Needless to say, but there will be a slight delay in the next Bud release
 until I sort out this next bloody irritation.
 
Can you work around it by separating the aliases out into separate v1 and v2 d-files? Like version(D_Version2) { import v2types; } else { import v1types; } --bb
Sep 02 2007
prev sibling next sibling parent Witold Baryluk <baryluk smp.if.uj.edu.pl> writes:
Dnia Sun, 2 Sep 2007 22:50:32 +1000
Derek Parnell <derek psych.ward> napisa=B3/a:

 Okay, I just don't get it.
=20
 This code below doesn't compile in V1 dmd.
=20
 version(D_Version2)
 {
     alias const(wchar)[] wstring;
     alias const(dchar)[] dstring;
 }
 else
 {
     alias char[] string;
     alias wchar[] wstring;
     alias dchar[] dstring;
 }
=20
=20
 I can understand why - because the first two alias declarations have
 invalid V1 syntax - but doesn't that make the whole D_Version2 thing
 pointless?
Unfortunetly this is correct behavior. Even when D_Version2 is undefined, anything which is inside must be syntacticly correct. const(wchar) is incorrect for D1. :/ --=20 Witold Baryluk, aleph0 MAIL: baryluk smp.if.uj.edu.pl JID: movax jabber.autocom.pl
Sep 02 2007
prev sibling next sibling parent reply 0ffh <spam frankhirsch.net> writes:
Derek Parnell wrote:
 This code below doesn't compile in V1 dmd.
 [...]
 I can understand why - because the first two alias declarations have
 invalid V1 syntax - but doesn't that make the whole D_Version2 thing
 pointless?
Um, I see it's a pain. Surely you know the string mixin workaround? Regards, Frank
Sep 02 2007
next sibling parent 0ffh <spam frankhirsch.net> writes:
0ffh wrote:
 Um, I see it's a pain. Surely you know the string mixin workaround?
Someone posted it somewhere at some time. I currently use this for strings: ---<snip>--- version (D_Version2) { mixin("alias invariant(char)* icptr;"); alias char* cptr; } else { alias char* icptr; alias char* cptr; alias char[] string; } ---<snap>--- Or were you just complaining about the lack of elegance here? Regards, Frank
Sep 02 2007
prev sibling parent Kirk McDonald <kirklin.mcdonald gmail.com> writes:
0ffh wrote:
 Derek Parnell wrote:
 
 This code below doesn't compile in V1 dmd.
 [...]
 I can understand why - because the first two alias declarations have
 invalid V1 syntax - but doesn't that make the whole D_Version2 thing
 pointless?
Um, I see it's a pain. Surely you know the string mixin workaround? Regards, Frank
For the record, the string mixin workaround looks like this: version (D_Version2) { mixin("alias const(char)* c_str;"); } else { alias char* c_str; } You can find this code near the top of the Python header. http://dsource.org/projects/pyd/browser/trunk/infrastructure/python/python.d So far as I can tell, I was the first person to come up with (or at least use) this workaround, but others may have come up with it on their own. -- Kirk McDonald http://kirkmcdonald.blogspot.com Pyd: Connecting D and Python http://pyd.dsource.org
Sep 02 2007
prev sibling parent torhu <no spam.invalid> writes:
Derek Parnell wrote:
 Okay, I just don't get it.
 
 This code below doesn't compile in V1 dmd.
 
 version(D_Version2)
 {
     alias const(wchar)[] wstring;
     alias const(dchar)[] dstring;
 }
 else
 {
     alias char[] string;
     alias wchar[] wstring;
     alias dchar[] dstring;
 }
 
 
 I can understand why - because the first two alias declarations have
 invalid V1 syntax - but doesn't that make the whole D_Version2 thing
 pointless?
 
Have you read this thread? Thomas Kuehne explains how to write code that works in both D 1 and 2. http://www.digitalmars.com/d/archives/digitalmars/D/supporting_DMD-1.016_and_DMD-2.000_with_the_same_source_code_54628.html
Sep 02 2007