www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Cross-platform and D

reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
If you mean to write a portable D library,
then please try to avoid hardcoding linux...


Something that should work is:

 version(Windows)
 {
      // Win32 API stuff
 }
 version (Unix)
 {
      // POSIX API stuff
 }

But if you use "linux", then your code will *not* compile on BSD - even if it is plain old POSIX ? If you *do* use Linux-specific system / OS values, then by all means continue to use "version(linux)" And if you need stuff specific to GDC / GCC, then you can use the handy "version(GNU)" that it sets... But otherwise, "version(Unix)" should do just fine ? --anders PS. Apple Mac OS X is such a BSD variant... (called Darwin) http://developer.apple.com/darwin/projects/darwin/faq.html
Nov 22 2004
parent reply Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
Anders F Björklund schrieb am Mon, 22 Nov 2004 11:36:53 +0100:
 If you mean to write a portable D library,
 then please try to avoid hard coding linux...


 Something that should work is:

 version(Windows)
 {
      // Win32 API stuff
 }
 version (Unix)
 {
      // POSIX API stuff
 }

But if you use "linux", then your code will *not* compile on BSD - even if it is plain old POSIX ? If you *do* use Linux-specific system / OS values, then by all means continue to use "version(linux)" And if you need stuff specific to GDC / GCC, then you can use the handy "version(GNU)" that it sets... But otherwise, "version(Unix)" should do just fine ?

Actually it isn't fine. GDC defines linux(where appropriate) and Unix - in contrast DMD only defines linux. For the time being everyone should add # version(linux){ # version=Unix; # } into the head of each source file ... Seems to be worth a feature request, doesn't it? Thomas
Nov 22 2004
parent =?UTF-8?B?QW5kZXJzIEYgQmrDtnJrbHVuZA==?= <afb algonet.se> writes:
Thomas Kuehne wrote:

But otherwise, "version(Unix)" should do just fine ?

Actually it isn't fine. GDC defines linux(where appropriate) and Unix - in contrast DMD only defines linux. For the time being everyone should add

Aargh! That's even worse than the lower-case "linux"
 # version(linux){
 #     version=Unix;
 # }

It could well be that GDC already patches this in Phobos, so that was why I didn't even notice it... Note to self: test with the linux DMD compiler too. I suppose that:
 version(Windows)
 else /* version(Unix) */

could also be used as a work-around meanwhile ? (better than hardcoding "linux", at any rate)
 into the head of each source file ...
 Seems to be worth a feature request, doesn't it?

It does. Or even a bug report. --anders
Nov 22 2004