conditional compile else?

BlitzMax Forums/BlitzMax Programming/conditional compile else?

is there a way to say
?Win32
   function win32only()
?else
   function AllOtherPlatforms()
?

?

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.

well, yes, but I was hoping that the ? compiler directive had this functionality.

The code from zeedoktor achieves the same thing.

?Win32
	Print "Windows"
?Linux
	Print "Linux"
?MacOS
	Print "MacOS"
?
It's not like it's a lot of extra typing is it?

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.

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.

This seems to work:
?macos
	notwin32 = macos
?linux
	notwin32 = linux
?

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

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

This works:
?Win32
	Print "Hello Win32"
	Goto begin1
?
	Print "Hello Linux/MacOS"
? 
#begin1

?Linux
	Print "Hello Linux"
	Goto begin2
?
	Print "Hello Win32/MacOS"
? 
#begin2

?MacOS
	Print "Hello MacOS"
	Goto begin3
?
	Print "Hello Linux/Win32"
? 
#begin3
But it isn't pretty :)

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.

This may be of interest:
?Debug
	Print "Debug is On!"
?


Silly question, but what does the ? do?

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.

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.

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.

It isn't added to the EXE (AFAIK), but it IS parsed.

Fascinating. That seems totally illogical to me =]