Re: New keywords: ifdef, elsifdef, end ifdef
I wanted to follow up after reading my own post
First, the else keyword also works inside of an ifdef, elsifdef, else, end ifdef
structure.
Second, this is not just a nice addition to use, it will speed your code up in
any case where it is useful. How does it do it? Take this for example:
for i = 1 to 10000 do
if debug = 1 then
printf(1, "Loop iteration %i\n", {i})
end if
--- code
end for
Each iteration, the interpreter must check to see if debug is equal to 1. Now,
look at this example:
for i = 1 to 10000 do
ifdef debug then
printf(1, "Loop iteration %i\n", {i})
end ifdef
--- code
end for
The interpreter *never* checks if debug is on or off. How does it do it? During
the parsing of your source code, the ifdef keyword is found and instead of
"emitting" the code to the interpreter (IL code), the parser looks in a sequence
of defines to see if the define you requested exists. If so, then it ignores
itself (i.e. the ifdef debug then) and allows the parser to continue to "emit"
the code in it's own block to the interpreter (IL code). If it is not defined,
then the parser skips all code, not emiting IL code for the entire contained
block. Thus, the interpreter never even knows the code exists.
So, in the above example, if debug is not defined, then the interpreter thinks
the application looks like:
for i = 1 to 10000 do
--- code
end for
If debug is defined, then the interpreter thinks the application looks like:
for i = 1 to 10000 do
printf(1, "Loop iteration %i\n", {i})
--- code
end for
Again, I want to stress for those who did not read a few previous posts under a
different subject. This is *not* a pre-processor. A pre-process will slow things
down. This does not. A pre-processor will scan the source contents before the
parser ever get's it and filter out any unwanted code. Once the pre-processor is
done, it then sends it's processed code to the parser for the real scanning. The
new ifdef construct happens during the normal parse. It's use will only speed
things up, not slow them down. If you do not use the ifdef keyword then it will
have zero effect on your code.
--
Jeremy Cowgar
http://jeremy.cowgar.com
|
Not Categorized, Please Help
|
|