?DEFINE/?UNDEF problem

Previous topic - Next topic

MrTAToad

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"

Slydog

Is this a nested '?IFDEF' issue / bug I wonder?
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

MrTAToad

Yes, sounds like it.

MrTAToad

Aww - this little problem wasn't fixed in the update  :'(

Kitty Hello

no, sorry. That's one of the big ones.

Slydog

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.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

MrTAToad

My example just shows that ?UNDEF will undefine a ?DEFINE variable, even if the code isn't executed.

Slydog

#7
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.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

MrTAToad

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 :)

Kitty Hello

Ah. ?UNDEF was always executed. I fixed it and do an update now.