Shop OBEX P1 Docs P2 Docs Learn Events
Bug in $ifnused / $endif — Parallax Forums

Bug in $ifnused / $endif

Peter VerkaikPeter Verkaik Posts: 3,956
edited 2009-02-11 14:39 in General Discussion
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

Comments

  • BeanBean Posts: 8,129
    edited 2009-02-10 12:53
    Peter,
    · The conditional compiler directives cannot be nested.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There is a fine line between arrogance and confidence. Make sure you don't cross it...

    ·
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-02-10 13:28
    Ok, to be clear

    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
  • BeanBean Posts: 8,129
    edited 2009-02-11 12:51
    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...

    ·
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-02-11 13:35
    Bean,

    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
  • BeanBean Posts: 8,129
    edited 2009-02-11 13:53
    Okay, I can do that...
    You'll have to use a structure like:
    '{$ifuse subname}
      'code
    '{$endif}
    
     
    '{$ifnused subname}
      '{$ifdef sx18}
        'code
      '{$endif}
    '{$endif}
     
    '{$ifnused subname}
      '{$ifdef sx20}
        'code
      '{$endif}
    '{$endif}
     
    '{ifnused subname}
      '{$ifdef sx28}
        'code
      '{$endif}
    '{$endif}
    

    ·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...

    ·
  • BeanBean Posts: 8,129
    edited 2009-02-11 13:59
    Rev 2.00.10 is posted in the sticky thread.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There is a fine line between arrogance and confidence. Make sure you don't cross it...

    ·
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-02-11 14:11
    Bean,
    I usually use constructs like this

    '{$ifdef somename}
      'code
      '{$ifdef sx18}
        'code
      '{$endif}
      '{$ifdef sx20}
        'code
      '{$endif}
      '{$ifdef sx28}
        'code
      '{$endif}
      'code
    '{$endif}
    
     
     
    

    When I undefine somename, the inner ifdefs should not evaluate.
    Isn't that the "workaround" you proposed?

    regards peter
  • BeanBean Posts: 8,129
    edited 2009-02-11 14:16
    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.

    '{$ifdef somename}
      'code
      '{$ifdef sx18}
        'code
      '{$endif}    <- anything after this ALWAYS compiles regardless of somename or SX18                                    
    
    



    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
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-02-11 14:27
    Ok so I will have to use

    '{$ifdef somename}
      'code
    '{$endif}
    '{$ifdef somename}
      '{$ifdef sx18}
        'code
      '{$endif}
    '{$endif}
    '{$ifdef somename}
      '{$ifdef sx20}
        'code
      '{$endif}
    '{$endif}
    '{$ifdef somename}
      '{$ifdef sx28}
        'code
      '{$endif}
    '{$endif}
    '{$ifdef somename}
      'code
    '{$endif}
    
    

    A bit awkward but if it works for now...
    It would still work with real nesting.

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-02-11 14:39
    I can confirm that with v2.00.10·the construct
    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
Sign In or Register to comment.