1. Ver 4.0 ifdef question

I understand that ifdef is a great feature for writing the interpreter 
 
because you will always know what operating system it will run on and 
 
can set define for that operating system. 
 
 
 
 
But 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 ??????? 
 

new topic     » topic index » view message » categorize

2. Re: Ver 4.0 ifdef question

bernie said...

I understand that ifdef is a great feature for writing the interpreter 
 
because you will always know what operating system it will run on and 
 
can set define for that operating system. 
 
 
 
 
But 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 ??????? 
 

It usually does.

ifdef in a library is processed when the library code is being parsed.

If the library is parsed on the machine that will execute its code, then it knows on which OS it is running.

If you translate the library, then you'll need to cross-compile for each target platform, and the translator takes care of the platform dependent ifdefs. Obviously, it doesn't know about ifdef tags that are not platform related, like SAFE, assuming their current status. You need to add command line -D switches for that.

If you bind your library, then something may go wrong. But, with the translator being free, why bind at all? You need a C compiler to translate, but you require your users to have the interpreter if you bind. bind? -shroud_only is still useful for debugging or performance fine tuning.

CChris

new topic     » goto parent     » topic index » view message » categorize

3. Re: Ver 4.0 ifdef question

CChris said...
bernie said...

I understand that ifdef is a great feature for writing the interpreter 
 
because you will always know what operating system it will run on and 
 
can set define for that operating system. 
 
 
 
 
But 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 ??????? 
 

It usually does.

ifdef in a library is processed when the library code is being parsed.

If the library is parsed on the machine that will execute its code, then it knows on which OS it is running.

If you translate the library, then you'll need to cross-compile for each target platform, and the translator takes care of the platform dependent ifdefs. Obviously, it doesn't know about ifdef tags that are not platform related, like SAFE, assuming their current status. You need to add command line -D switches for that.

If you bind your library, then something may go wrong. But, with the translator being free, why bind at all? You need a C compiler to translate, but you require your users to have the interpreter if you bind. bind? -shroud_only is still useful for debugging or performance fine tuning.

CChris

 
   I don't think you understand my question. 
 
I write a cross platform library that can be used on the following platforms. 
 
DOS 
WINDOWS 
LINUX 
 
A user can include it on any platform. 
 
How does the library know what platform it is running on without the platform() ??? 
 
What big advantage does removing platform() from the interpeter have ??? 
 
 

new topic     » goto parent     » topic index » view message » categorize

4. Re: Ver 4.0 ifdef question

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 message » categorize

5. Re: Ver 4.0 ifdef question

bernie said...

How does the library know what platform it is running on without the platform() ???

You would have to set a variable, probably... or use platform(), even though it's deprecated. Something like:

integer myOS = UnknownOS 
 
ifdef WIN32 then 
  myOS = Win32 
else 
  myOS = Linux 
else 
  myOS = FreeBSD 
else 
  myOS = MacOSX 
end if 
new topic     » goto parent     » topic index » view message » categorize

6. Re: Ver 4.0 ifdef question

euphoric said...

You would have to set a variable, probably... or use platform(), even though it's deprecated.

**STOP STOP STOP** News Flash: The platform() function is not, repeat, not being deprecated or removed.

euphoric said...

Something like:

integer myOS = UnknownOS 
 
ifdef WIN32 then 
  myOS = Win32 
else 
  myOS = Linux 
else 
  myOS = FreeBSD 
else 
  myOS = MacOSX 
end if 

Ok, now suppose one does this. What are you going to do with myOS? Maybe something like ...

if myOS = WIN32 then 
    puts(1, "Breaking Windows\n") -- Something that must only run in Windows 
else 
    puts(1, "Chasing penguins\n") -- Something that must only run in 'nix 
end if 

This would cause a run-time test of the myOS variable each time. Using ifdef instead would generate smaller IL code and run faster.

ifdef WIN32 then 
    -- On 'nix boxes, this does not generate any IL. 
    puts(1, "Breaking Windows\n") -- Something that must only run in Windows 
else 
    -- On Windows boxes, this does not generate any IL. 
    puts(1, "Chasing penguins\n") -- Something that must only run in 'nix 
end ifdef 

I know which option I'd choose. blink

new topic     » goto parent     » topic index » view message » categorize

7. Re: Ver 4.0 ifdef question

bernie said...

I don't think you understand my question.

I write a cross platform library that can be used on the following platforms.

DOS 
WINDOWS 
LINUX 
A user can include it on any platform.

How does the library know what platform it is running on without the platform() ???

What big advantage does removing platform() from the interpeter have ???

Derek answered this incorrect assumption about the future of platform(), but since the question keeps coming up, maybe we need multiple answers, too. smile

platform() exists in 4.0. There are no plans to remove it. There was an incorrect statement in an earlier version of the docs.

Something that Derek didn't explicitly say is that the parser defines an ifdef (that's awkwardwhat's the correct wording for this?) for the native platform of the binary itself (exw.exe, exu, ec.exe, etc) by default. So however you run your code, it will know which platform it's running on because WIN or DOS or UNIX or LINUX or BSD or OSX (multiples on Unix-like OSes) will be defined.

Additional defs (which are application specific, or possibly 'special' ones like SAFE) can be defined either on the command line (-D <word>) or in the source code like this:

    with define MATT 

Matt

new topic     » goto parent     » topic index » view message » categorize

8. Re: Ver 4.0 ifdef question

mattlewis said...
bernie said...

I don't think you understand my question.

I write a cross platform library that can be used on the following platforms.

DOS 
WINDOWS 
LINUX 
A user can include it on any platform.

How does the library know what platform it is running on without the platform() ???

What big advantage does removing platform() from the interpeter have ???

Derek answered this incorrect assumption about the future of platform(), but since the question keeps coming up, maybe we need multiple answers, too. smile

platform() exists in 4.0. There are no plans to remove it. There was an incorrect statement in an earlier version of the docs.

Something that Derek didn't explicitly say is that the parser defines an ifdef (that's awkwardwhat's the correct wording for this?) for the native platform of the binary itself (exw.exe, exu, ec.exe, etc) by default. So however you run your code, it will know which platform it's running on because WIN or DOS or UNIX or LINUX or BSD or OSX (multiples on Unix-like OSes) will be defined.

Additional defs (which are application specific, or possibly 'special' ones like SAFE) can be defined either on the command line (-D <word>) or in the source code like this:

    with define MATT 

Matt

Thanks Everyone !
For your replys.
Bernie

new topic     » goto parent     » topic index » view message » categorize

9. Re: Ver 4.0 ifdef question

mattlewis said...

Additional defs .. can be defined

Yes, this is another reason that ifdef is better. You can define your own 'platform' version to run in.

ifdef ADULT then 
    puts(1, "Damn! You got blown apart and your body got scattered from here to Hell.\n") 
else 
    puts(1, "Oops! You fainted.\n") 
end ifdef 
puts(1, "Play again?\n") 

bind -D ADULT mygame (makes an Adult version) 
bind mygame (makes a 'G' version) 

new topic     » goto parent     » topic index » view message » categorize

10. Re: Ver 4.0 ifdef question

DerekParnell said...

Ok, now suppose one does this. What are you going to do with myOS?

Use it in the status bar or in a help window:

     You are running Windows 2010. 

I'm sure there are cases when setting a variable would be useful.

new topic     » goto parent     » topic index » view message » categorize

11. Re: Ver 4.0 ifdef question

euphoric said...
DerekParnell said...

Ok, now suppose one does this. What are you going to do with myOS?

Use it in the status bar or in a help window:

     You are running Windows 2010. 

I'm sure there are cases when setting a variable would be useful.

ifdef WIN32 
  sequence whereami = "You are running Windows 2010" 
else 
  sequence whereami = "You are using some form of not-Windows" 
end ifdef 
. . . 
set_status_text(whereami) 
new topic     » goto parent     » topic index » view message » categorize

12. Re: Ver 4.0 ifdef question

DerekParnell said...
mattlewis said...

Additional defs .. can be defined

Yes, this is another reason that ifdef is better. You can define your own 'platform' version to run in.

ifdef ADULT then 
    puts(1, "Damn! You got blown apart and your body got scattered from here to Hell.\n") 
else 
    puts(1, "Oops! You fainted.\n") 
end ifdef 
puts(1, "Play again?\n") 

bind -D ADULT mygame (makes an Adult version) 
bind mygame (makes a 'G' version) 

What!? You call that the Adult version? How about this:

<censored>

Matt

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu