Guideline for D1/2 compatible code?

Stewart Gordon smjg_1998 at yahoo.com
Sat Jan 17 14:19:00 PST 2009


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.


More information about the Digitalmars-d-learn mailing list