1. Where does 'DEBUG' come from?
- Posted by dcole Mar 06, 2011
- 1890 views
From the manual,
-- Example 1. -- if find("-DEBUG", command_line()) then writefln("Debug x=[], y=[]", {x,y}) end if -- Example 1. -- ifdef DEBUG then writefln("Debug x=[], y=[]", {x,y}) end ifdef
In the top example:
I see they are looking for the string "-Debug" in the command_line()
In the lower example:
What I don't understand is where did the uppercase DEBUG come from and where do we hope to find it?
Don Cole
2. Re: Where does 'DEBUG' come from?
- Posted by DerekParnell (admin) Mar 06, 2011
- 1883 views
From the manual,
-- Example 1. -- ifdef DEBUG then writefln("Debug x=[], y=[]", {x,y}) end ifdef
What I don't understand is where did the uppercase DEBUG come from and where do we hope to find it?
It comes from the Euphoria command line (or a eu.cfg) file.
e.g.
eui -D DEBUG myprog.ex
3. Re: Where does 'DEBUG' come from?
- Posted by dcole Mar 07, 2011
- 1823 views
[quote DerekParnell]
It comes from the Euphoria command line (or a eu.cfg) file.
e.g.
eui -D DEBUG myprog.ex
So ifdef is only useful if you are using command line or eu.cfg in you program. Other wise there is no need for it.
Also in the first example -DEBUG uses quotes. I the second example it does not. Why is that?
Don Cole
4. Re: Where does 'DEBUG' come from?
- Posted by jaygade Mar 08, 2011
- 1770 views
It comes from the Euphoria command line (or a eu.cfg) file.
e.g.
eui -D DEBUG myprog.ex
So ifdef is only useful if you are using command line or eu.cfg in you program. Other wise there is no need for it.
No. You can also have a line in your program:
with define DEBUG -- need to debug the next section of code
In order to define the symbol DEBUG and use it later in an ifdef statement.
And then you can always
without define DEBUG -- not debugging any more
Later on to bypass all of the ifdef DEBUG statements.
It's still your responsibility to wrap debugging code with ifdef though - the word DEBUG itself has no significance to the Euphoria interpreter. You could use LOG or CONOUT or anything else you could think of.
Also in the first example -DEBUG uses quotes. I the second example it does not. Why is that?
Don Cole
In the first example, your program is looking for a command line option called "-DEBUG". Like most other command line options it is the responsibility of your program to parse them out.
Your command line would look like this:
eui myprog.ex -DEBUGAnd the string "-DEBUG" will be passed to your program and can be accessed by the command_line() function.
In the second example, the interpreter sees the "-D" on the command line and says "oh, the next word is a word which I should define" and it takes the word "DEBUG" and defines it so it can be used in an ifdef statement.
eui -D DEBUG myprog.ex
Your program sees no options on its own command line, eui eats up the "-D DEBUG" as its own option. (Note: you can access the interpreter command line options via the function option switches())
I think that part of the confusion comes from using the word "DEBUG" in both examples, making them seem related. They aren't really.
Another thing which makes ifdef useful is that any code wrapped by an ifdef is only parsed if the define referred to is true. Otherwise the code is not generated. So in the first example, the "if find("-DEBUG", command_line())" statement is run regardless of whether "-DEBUG" exists on the command line or not. In the second example, if "-D DEBUG" is not on the command line and "DEBUG" is not defined anywhere else, then the parser just skips to the "end ifdef" statement.
Thirdly, Euphoria defines some of its own words, as the manual page states. So you can write version-specific, platform-specific, or feature-specific code and have it wrapped conditionally.
Here, try this - type in the following program exactly as it is written:
ifdef DEBUG then an illegal statement end ifdef puts(1, "Success!\n")
Now, if you have a 4.0 or better interpreter installed, type:
eui test-ifdef.exYou should get "Success!" as an output.
Now type:
eui -D DEBUG test-ifdef.exAnd you should get an error.
You can't do that with a normal "if" statement.
Now, that's not a very useful example, but let's say you used "ifdef EU_4_1" as a test and then included some 4.1 only code within the ifdef. Now, you can guard for that and write alternate code for earlier versions of the interpreter.
There are other applications as well. I think that biggest usage so far has been to determine whether eui is running under LINUX or WINDOWS, or whether a program is being translated (EUC) or interpreted (EUI).
Does that answer your question?
To simplify, in the second example, the "DEBUG" comes from either the interpreter command line switch "-D" (your program never sees "-D DEBUG" in its own command line, the interpreter eats it up), from your eu.cfg file, or from within your program in a "with define" directive.
5. Re: Where does 'DEBUG' come from?
- Posted by dcole Mar 09, 2011
- 1662 views
Thank you jaygade,
When I run your program I get Success!
When I type eui test-ifdef.ex
I get Can't open test-ifdef.ex
I'm using euphoria-40b4.
Don Cole
6. Re: Where does 'DEBUG' come from?
- Posted by jaygade Mar 09, 2011
- 1679 views
Heh, sorry. I meant to have my example program saved as "test-ifdef.ex". I meant to "eui" whatever-you-named-the-program.
7. Re: Where does 'DEBUG' come from?
- Posted by DanM Mar 09, 2011
- 1679 views
I can't take it any longer! De debil makes me do it!
Debug comes from...DE EGG!
(sorry 'bout that!)
Dan