www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Guideline for D1/2 compatible code?

reply Trass3r <mrmocool gmx.de> writes:
Are there any guidelines for writing code compilable with both dmd 1.x and  
2.x?
Jan 17 2009
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Trass3r wrote:
 Are there any guidelines for writing code compilable with both dmd 1.x 
 and 2.x?
This is to make a library usable by users of either, I presume? I can give a few: - Have a module to define types for such things as pointers/arrays that will be const in D2. - Use version(D_Version2) for bits of code that need to be different between the two. - Use string mixins to include D2 code that is syntactically illegal under D1. This is the approach used by SDWF. http://pr.stewartsplace.org.uk/d/sdwf/ Note also if you're compiling a Windows GUI app, that WinMain will need to be defined differently. Again, a dual-mode WinMain is bundled with SDWF. http://d.puremagic.com/issues/show_bug.cgi?id=2580 Stewart.
Jan 17 2009
parent reply Trass3r <mrmocool gmx.de> writes:
Am 17.01.2009, 23:19 Uhr, schrieb Stewart Gordon <smjg_1998 yahoo.com>:

 Trass3r wrote:
 Are there any guidelines for writing code compilable with both dmd 1.x  
 and 2.x?
This is to make a library usable by users of either, I presume?
Yes.
 - Have a module to define types for such things as pointers/arrays that  
 will be const in D2.
Yeah, using the following atm: alias char[] string; alias const(char)[] cstring; alias invariant(char)[] istring;
 - Use version(D_Version2) for bits of code that need to be different  
 between the two.

 - Use string mixins to include D2 code that is syntactically illegal  
 under D1.
I'd like to use "alias char[] string", but dmd complains about conflicts with the builtin "alias invariant(char)[] string" Is there any way to redefine string in the scope of the library? I know I could simply use another name or use char[] but if it's possible to redefine it, I'd love to do that.
Jan 18 2009
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Trass3r wrote:
<snip>
 I'd like to use "alias char[] string", but dmd complains about conflicts 
 with the builtin "alias invariant(char)[] string"
 
 Is there any way to redefine string in the scope of the library?
I don't think so.
 I know I could simply use another name or use char[] but if it's 
 possible to redefine it, I'd love to do that.
You're best off not trying to mess with type definitions like this. It would confuse anybody who tries to use your library. Just use char[] as it is - it'll be understood by everyone and keeps things simple. Stewart.
Jan 18 2009