[Mono-list] Making code conditional on "not running on mono"?

Paolo Molaro lupus@ximian.com
Mon, 19 May 2003 11:52:22 +0200


On 05/16/03 Stuart Ballard wrote:
> >We do somthing similar in nant. Except we use #ifdef mono.
> >Another way to test if you are on windows it to check the value of 
> >DirectorySeperatorchar. That won't help if you're trying to test for 
> >mono since you cold be on mono on wondows.
> 
> Hey cool, I didn't know that C# had a preprocessor :)
> 
> Question to the Mono developers: Would it be worth making "/d:mono" or 
> "/d:mcs" a default in mcs? That would make it possible to write code 
> that compiles differently on Mono without having to specialcase your 
> build scripts.
> 
> (this seems analagous to the fact that you can assume things like 
> "#ifdef linux" and "#ifdef gcc" in C and get meaningful results without 
> having to explicitly -D them on the commandline)

Note: mcs already defines a symbol you can use to do different things if
you're compiling with mcs (it has nothing to do with the binary being
then run with mono or another runtime, so it's useless for your purpouse).

Using something like /d:mono is not a good idea either, unless you think
of it like a temporary workaround. Almost always, you should do a
runtime check instead, so that you can build a single binary that works
on all the runtimes. Also, don't forget to file bug reports for the
issues you find in bugzilla, so that we know they need fixing.
Once the bug is fixed or the feature is implemented, your code will take
advantage of it without modifications.

lupus

-- 
-----------------------------------------------------------------
lupus@debian.org                                     debian/rules
lupus@ximian.com                             Monkeys do it better