GLBasic forum

Main forum => Bug Reports => Topic started by: MrTAToad on 2010-Nov-03

Title: ?DEFINE/?UNDEF problem
Post by: MrTAToad on 2010-Nov-03
With the following :

Code (glbasic) Select
?IFDEF WIN32
?WARNING "Defining TEST"
?DEFINE TEST

?IFDEF TEST
?WARNING "Test is defined"
?ELSE
?WARNING "Test is not defined"
?ENDIF
?ELSE
?WARNING "In else"
?UNDEF TEST
?ENDIF

?IFDEF TEST
?WARNING "Test is defined"
?ELSE
?WARNING "Test is NOT defined"
?ENDIF


TEST is being defined.  However, even though the else part isn't actually being executed (or doesn't appear to be), TEST is being undefined, with the result being :

Code (glbasic) Select
"TestTType.gbas"(2) warning : preprocessor warning :
"Defining TEST"

"TestTType.gbas"(6) warning : preprocessor warning :
"Test is defined"

"TestTType.gbas"(18) warning : preprocessor warning :
"Test is NOT defined"
Title: Re: ?DEFINE/?UNDEF problem
Post by: Slydog on 2010-Nov-04
Is this a nested '?IFDEF' issue / bug I wonder?
Title: Re: ?DEFINE/?UNDEF problem
Post by: MrTAToad on 2010-Nov-04
Yes, sounds like it.
Title: Re: ?DEFINE/?UNDEF problem
Post by: MrTAToad on 2010-Nov-25
Aww - this little problem wasn't fixed in the update  :'(
Title: Re: ?DEFINE/?UNDEF problem
Post by: Kitty Hello on 2010-Nov-25
no, sorry. That's one of the big ones.
Title: Re: ?DEFINE/?UNDEF problem
Post by: Slydog on 2010-Nov-25
I didn't see an example of using 'AND' in a '?IFDEF' command, but you could restructure the nest using 'AND' if that is available. 
If not, would it be easier to add an 'AND' option rather than making nested directives possible?

Such as:
Code (glbasic) Select

?IFDEF WIN32
   ?WARNING "Defining TEST"
   ?DEFINE TEST
?ENDIF

?IFDEF WIN32 AND ?IFDEF TEST   
      ?WARNING "Test is defined"
?ELSE
      ?WARNING "Test is not defined"
?ENDIF

?IFNDEF WIN32 AND ?IFNDEF TEST
   ?WARNING "In else"
   ?UNDEF TEST
?ENDIF

?IFDEF TEST
   ?WARNING "Test is defined"
?ELSE
   ?WARNING "Test is NOT defined"
?ENDIF


Something like that.  I don't really know what you are trying to do, so the above probably doesn't make sense.
Title: Re: ?DEFINE/?UNDEF problem
Post by: MrTAToad on 2010-Nov-25
My example just shows that ?UNDEF will undefine a ?DEFINE variable, even if the code isn't executed.
Title: Re: ?DEFINE/?UNDEF problem
Post by: Slydog on 2010-Nov-25
It gets weirder.  And it's not a nested ?IFDEF bug, as the following has no nests.

This code:
Code (glbasic) Select
?IFDEF WIN32
   ?WARNING "Defining TEST"
   ?DEFINE TEST
//?ELSE   
//?UNDEF TEST
?ENDIF

?IFDEF TEST
   ?WARNING "Test is defined"
?ELSE
   ?WARNING "Test is NOT defined"
?ENDIF


produces this output:
Code (glbasic) Select
"IFDEF.gbas"(2) warning : preprocessor warning :
"Defining TEST"

"IFDEF.gbas"(11) warning : preprocessor warning :
"Test is NOT defined"


But remove the comments:
Code (glbasic) Select
?IFDEF WIN32
   ?WARNING "Defining TEST"
   ?DEFINE TEST
?ENDIF

?IFDEF TEST
   ?WARNING "Test is defined"
?ELSE
   ?WARNING "Test is NOT defined"
?ENDIF


produces this:
Code (glbasic) Select
"IFDEF.gbas"(2) warning : preprocessor warning :
"Defining TEST"

"IFDEF.gbas"(7) warning : preprocessor warning :
"Test is defined"


You can't comment precompiler directives?

[Edit]
It's like any reference to '?UNDEF' (comment out or not) ignores any '?IF' structures and is always executed.
Title: Re: ?DEFINE/?UNDEF problem
Post by: MrTAToad on 2010-Nov-25
I think any ?UNDEF reached will remove the defined variable no matter if its in the same block as ?DEFINE or not - and no matter whether its commented or not.

I had thought it was an ?ELSE problem, but I think you've shown it isn't :)
Title: Re: ?DEFINE/?UNDEF problem
Post by: Kitty Hello on 2010-Nov-26
Ah. ?UNDEF was always executed. I fixed it and do an update now.