conditional compile else?

BlitzMax Forums/BlitzMax Programming/conditional compile else?

Perturbatio(Posted 2004) [#1]
is there a way to say
?Win32
   function win32only()
?else
   function AllOtherPlatforms()
?

?


zeedoktor(Posted 2004) [#2]
Const PLATFORM = "Win32"

If PLATFORM = "Win32"
...
End if

That should work? AFAIK, it will only compile if the parts of the if statement that evaluate to true.


Perturbatio(Posted 2004) [#3]
well, yes, but I was hoping that the ? compiler directive had this functionality.


matt!(Posted 2004) [#4]
The code from zeedoktor achieves the same thing.


fredborg(Posted 2004) [#5]
?Win32
	Print "Windows"
?Linux
	Print "Linux"
?MacOS
	Print "MacOS"
?
It's not like it's a lot of extra typing is it?


Perturbatio(Posted 2004) [#6]
No, that's not, but the more code you want to conditionally compile, the more annoying it becomes.

*EDIT*

And let's imagine for a moment that BMax gets ported to WinCE and PalmOS and heck, the gameboy.

you'd then have 6 os's to do instead of 3.


Hotcakes(Posted 2004) [#7]
working on zeedoktor's idea...

?Win 32
  Const PLATFORM=1
?Linux
  Const PLATFORM=2
?MacOS
  Const PLATFORM=3
?
If PLATFORM=1
  function win32only()
else
  function AllOtherPlatforms()
endif


Or something to that effect.


fredborg(Posted 2004) [#8]
This seems to work:
?macos
	notwin32 = macos
?linux
	notwin32 = linux
?

?Win32
	Print "Windows"
?notwin32
	Print "Something Else"
?
Edit: But it doesn't


Damien Sturdy(Posted 2004) [#9]
A little off topic here:

i recon someone gets it working on a Gamecube sometime (it uses the PPC processor, no? and they just managed to get linux working on a GC....)

Hey.. thats another question.. would bmax run on linux running on a mac? :S


fredborg(Posted 2004) [#10]
This works:
But it isn't pretty :)


flying willy(Posted 2004) [#11]
Hi,

You're all assuming that we're going to have full access to the other machines.

Consider Perturbatio's point another way.

What if you only had a win32 pc and had friends with registered bmax to compile for linux/mac ? it would be nice to have a command that returns the id or something.

It's not essential but nice all the same.


fredborg(Posted 2004) [#12]
This may be of interest:
?Debug
	Print "Debug is On!"
?



flying willy(Posted 2004) [#13]
Silly question, but what does the ? do?


Michael Reitzenstein(Posted 2004) [#14]
Const PLATFORM = "Win32"

If PLATFORM = "Win32"
...
End if

That should work? AFAIK, it will only compile if the parts of the if statement that evaluate to true.

(And all variations)

Normally, you want to call different functions and import different libraries etc on different platforms, and ? is a preprocessor directive so anything thrown out the compiler will never see. Blocks of code wrapped in If <0> will still be parsed. ? will allow you to import different source files depending on the platform. If <Const> will not.


Hotcakes(Posted 2004) [#15]
Hey.. thats another question.. would bmax run on linux running on a mac? :S

I believe the exes are x86 exes not ppc ones, so probably not. You might get mac exes running under mac linux? But then you may as well just run macos ;]

? will allow you to import different source files depending on the platform. If <Const> will not.

Why not? I still don't understand the difference. If 0=1 doesn't get compiled... Or does it? It shouldn't.


Michael Reitzenstein(Posted 2004) [#16]
It isn't added to the EXE (AFAIK), but it IS parsed. Try to compile this:

If 0 Then (*&%*$#&%(#^#$%#$%


Further, Import must appear at the top of a source file, so:

If Win32

	Import "Win32Code.bmx"

ElseIf Linux
	
	Import "LinuxCode.bmx"

Else
	
	Import "MacOSCode.bmx"

Endif


Will not work. You can use Include in this way, though.


Hotcakes(Posted 2004) [#17]
It isn't added to the EXE (AFAIK), but it IS parsed.

Fascinating. That seems totally illogical to me =]