New keywords: ifdef, elsifdef, end ifdef

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

Ok, in SVN revision 452, there are 2 new keywords. ifdef and elsifdef. The ifdef
is combined with an existing keyword, end, to make a complete set of conditional
compilation keywords.

A quick rundown:

1. Setting defines can be done in 2 ways:
1a..... with define=debug
....... this can be given multiple times to define more than one item
1b..... exu/ecu, ex/exw/exwc/ecw -D debug
....... -D parameter can be given multiple times to define more than one item

2. Clearing defines can be done with without:
1a..... without define=debug
....... this turns off the debug define.

3. Predefined "defines"
2a..... Current operating system (WIN32, DOS32, LINUX, FREEBSD)
2b..... Current Euphoria version (EU400)

4. ifdef/elsifdef/end ifdef work on static defines. You cannot execute dynamic
code in your ifdef/elseifdef.

A few examples:

ifdef debug then
    puts(1, "DEBUG\n")
end ifdef


exwc myprog.e --- no output
exwc -D debug myprog.e ---- "DEBUG"

with define=debug

ifdef debug then
    puts(1, "DEBUG\n")
end ifdef


exwc myprog.e --- "DEBUG"

Conditional includes

ifdef debug then
    include safe.e
else
    include machine.e
end ifdef


platform() replacement

sequence name

ifdef WIN32 then
    name = "Windows"
    global procedure say_hello()
        puts(1, "Hello from Windows!\n")
    end procedure
elsifdef LINUX then
    name = "Linux"
    global procedure say_hello()
        puts(1, "Hello from Linux!\n")
    end procedure
elsifdef DOS32 then
    name = "DOS"
    global procedure say_hello()
        puts(1, "Hello from DOS!\n")
    end procedure
end ifdef

say_hello()
puts(1, "You are on " & name & "\n")


with/without

with define=debug
if debug then
    puts(1, "Hello Debug\n")
end ifdef

without define=debug
if debug then
    puts(1, "Serious error, you should not be here!\n")
end ifdef


Things you *cannot* do:

sequence name
name = prompt_string("Enter style:")
ifdef name = "SIMPLE" then
end ifdef

ifdef myfunc() then
end ifdef

ifdef age = 32 then
end ifdef


All three of the above are dynamic. i.e. it depends on code to be executing,
thus those are decisions that can take place only in the interpreter, not at
parse time. If you need the above, then you use the normal if/elsif/else/end if
statements.

This is in SVN right now for anyone who wishes to test it, play with it. There
is a unit test added for it: tests/t_condcmp.e ... 672 tests now and counting!

--
Jeremy Cowgar
http://jeremy.cowgar.com

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

Search



Quick Links

User menu

Not signed in.

Misc Menu