Re: Ver 4.0 ifdef question

new topic     » goto parent     » topic index » view thread      » older message » newer message
bernie said...

if ifdef does not operate at run-time and there is no longer a platform()
then how does a cross platform library no what operating system it's
running on ???????

Firstly, platform() is not going away. There will be a platform() built-in routine in v4 and beyond. If only for source code compatibility reasons.

The ifdef executes at parse-time, which is a once off operation. The output of parse then either executed, bound, or compiled depending on which tool you use.

If executing (using the interpreter) then ifdef is superior to platform() because it makes the application run faster and generates smaller IL output.

for i = 1 to 100 do 
  if platform() = WIN32 then -- (this gets tested 100 times) 
     . . . 
  else                       -- (this executes a jump to the end-if 100 times) 
     . . .                   -- (on non-Windows platforms, the IL for this is added to the program) 
  end if 
end for 

However ...

for i = 1 to 100 do 
  ifdef WIN32 then -- (this gets tested once, at parse time) 
     . . . 
  else             -- (this executes a jump to the end-ifdef once, at parse time) 
     . . .         -- (on non-Windows platforms, the IL for this is not generated) 
  end ifdef 
end for 

So, in the case of the interpreter, one can always use ifdef instead of platform() because the source code is distributed to the environment it is run on. In other words, you can write the source code on a Windows box and distribute it to a Linux box and the Linux interpreter will understand it just fine.

Now, I assume by "cross platform" you mean that you are binding or compiling source code on a (for example) Windows box, trying to create an executable designed to run on a Linux box.

Currently, Euphoria doesn't really support this, and that includes v3.1. The use of platform() does not help here because of the way it is implemented - it is more like a constant rather than a function call. By this I mean that if you bind source on a Windows box, the generated IL is hard-coded as a Windows IL. For example ...

if platform() = WIN32 then 

When bound using the Windows binder, this is equivalent to

if 2 = 2 then  

But when bound using the Linux binder, this is equivalent to

if 3 = 2 then  

This means that if your target platform is Linux, you need to bind it using the Linux binder.

I believe that compiling (translating to C then using a C compiler to create a machine-code executable) is a similar situation. That is, if your target platform is Windows, then you need to compile on a Windows box, and likewise for Linux targets.

This has nothing to do with v3 verse v4 functionality. Both work the same in this respect. (of course I could be wrong here as I've never actually tried to do this)

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu