IfDef40

ifdef verses platform()

Platform is going to remain however it's usage will slowly dwindle as we now have a better construct. The new method is the ifdef facility, which does platform and other conditional compilation checks. You will find that ifdef is superior to platform() because it generates smaller IL output and makes programs run faster.

An example replacement of platform():

include misc.e

if platform() = LINUX then
    puts(1, "Linux\n")
elsif platform() = WIN32 then
    puts(1, "Windows\n")
elsif platform() = DOS32 then
    puts(1, "DOS\n")
else
    puts(1, "Unknown OS\n")
end if

New code:

include misc.e

ifdef LINUX then
    puts(1, "Linux\n")
elsifdef WIN32 then
    puts(1, "Windows\n")
elsifdef DOS32 then
    puts(1, "DOS\n")
else
    puts(1, "Unknown OS\n")
end ifdef

The main benefits are

  • platform() generates IL which is executed every time the program sees 'platform()', but ifdef is only executed once and the result is 'remembered' so it does have to test it again during the running of the program.
  • When using platform(), the source code after the 'if' and 'else' generates IL code, but with ifdef, any source code that is meant to get run on a different platform, just does not get IL code generated for it, thus making the parser output smaller.

For all the benefits of ifdef please see the ifdef statement in the manual.

Search



Quick Links

User menu

Not signed in.

Misc Menu