Bug in $ifnused / $endif
Peter Verkaik
Posts: 3,956
Bean,
In the attached library I use
'{$ifuse subname}
· 'code
'{$endif}
'{$ifnused subname}
· '{$ifdef sx18}
··· 'code
· '{$endif}
· '{$ifdef sx20}
··· 'code
· '{$endif}
· '{$ifdef sx28}
··· 'code
· '{$endif}
'{$endif}
I have device sx28. When I·use subname,·I expect the code for ifnused not to·be compiled.
However, the code for sx28 does get compiled. And I get a compile error when not·using subname
(ENDSUB not in SUB).
Please check it out.·The conditional compilation is something libraries depend on.
regards peter
In the attached library I use
'{$ifuse subname}
· 'code
'{$endif}
'{$ifnused subname}
· '{$ifdef sx18}
··· 'code
· '{$endif}
· '{$ifdef sx20}
··· 'code
· '{$endif}
· '{$ifdef sx28}
··· 'code
· '{$endif}
'{$endif}
I have device sx28. When I·use subname,·I expect the code for ifnused not to·be compiled.
However, the code for sx28 does get compiled. And I get a compile error when not·using subname
(ENDSUB not in SUB).
Please check it out.·The conditional compilation is something libraries depend on.
regards peter
Comments
· The conditional compiler directives cannot be nested.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There is a fine line between arrogance and confidence. Make sure you don't cross it...
·
We cannot use $ifused or $ifnused within a $ifused/$ifnused.
But we can use $ifdef and $ifndef within $ifused/$ifnused,
and we can use $ifdef and $ifndef within $ifdef/$ifndef
I checked the last two·and that appears to be the case.
regards peter
It looks like you can put one condition inside another, but the first '{$ELSE} or '{$ENDIF} encountered will end ALL of the conditions.
I don't think it matters if it is a '{$IFDEF}, '{$IFNDEF}, '{$IFUSED} or '{$IFNUSED}.
There is only a single flag in the compiler to indicate if commands should be compiled or not. Each new condition encountered sets or resets the flag.
NOTE:·New conditions are processed EVEN IF they are in a section that is not compiled. I might be able to change this easily if that could be a "work-around" for now ?
I will look into enhancing the compiler conditionals so that they can be nested.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There is a fine line between arrogance and confidence. Make sure you don't cross it...
·
I noticed that. When I have my surrounding conditional set to true (meaning do compile),
the inner blocks are compiled or not correctly. When my surrounding conditional is set false
(do not compile) but there is an inner conditional that is true, parts that should not compile
do get compiled, resulting in all kinds of errors. Mostly about undefined variables
which are defined in another block that correctly did·not compile.
If you can prevent inner conditionals to be evaluated for non-compiled blocks
that would be an improvement.
But a very limited·nesting (3 or 4 levels) is welcomed and should be sufficient.
regards peter
You'll have to use a structure like:
·All the '{$ENDIF} lines are not really needed for this rev, but when I DO allow full nesting it will still work right.
·I will post the new rev shortly.
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There is a fine line between arrogance and confidence. Make sure you don't cross it...
·
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There is a fine line between arrogance and confidence. Make sure you don't cross it...
·
I usually use constructs like this
When I undefine somename, the inner ifdefs should not evaluate.
Isn't that the "workaround" you proposed?
regards peter
No, the first '{$endif} (or '{$else} )will actually end the whole conditional compilation.
So you'll need to keep specifying the '{ifdef somename} for each condition.
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There is a fine line between arrogance and confidence. Make sure you don't cross it...
Post Edited (Bean (Hitt Consulting)) : 2/11/2009 2:22:29 PM GMT
A bit awkward but if it works for now...
It would still work with real nesting.
regards peter
of my previous post does indeed not compile
any code when somename is not defined.
And only compiles for the used sx device when
somename is defined.
Thanks Bean.
regards peter