Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Enumeration with 'strict' attribute

swtroelofs
2016-08-02
2016-09-02
  • swtroelofs - 2016-08-02

    Hi everybody,

    I declare the following enumeration:

    {attribute 'strict'}
    TYPE myEnum :
    (
    Β  Β red, yellow, green
    );
    END_TYPE
    

    Does anybode know the exact function of the Strict attribute?

    And why does this code not compile:

    PROGRAM myPOU
    VAR
    Β  Β x:BOOL;
    Β  Β e:myEnum;
    END_VAR
    e := SEL(x, myEnum.green, myEnum.red);
    

    I get this error:
    C0358: 'SEL(x, myEnum.green, myEnum.red)' is not a valid value for strict ENUM type 'myEnum'
    When I remove the 'strict' attribute, the code compiles normally.
    Any ideas? Thanks!

     
  • rickj - 2016-08-03

    You could try using the instance name

    Zitat:
    e := SEL(x, e.green, e.red);

     
  • Mikado - 2016-08-24

    Bump

    Was does {attribute 'strict'} do and can it be used outisde enums?

     
  • TimvH

    TimvH - 2016-09-02

    See the CODESYS Help:

    NOTICE!
    As of CODESYS V3.5 SP7, each enumeration that you add to a project receives the 'strict' attribute automatically in the line above the TYPE declaration. For compiler versions >=3.5.7.0 , this causes compile errors in the following cases:

    Arithmetic operation with variables of the enumeration type
    Assignment of a constant value to a variable of the enumeration type, in which the constant does not correspond to an enumeration value
    Assignment of a non-constant value to a variable of the enumeration type, in which the non-constant has another data type than the enumeration type
    The attribute can also be added explicitly or removed.

    Syntax: {attribute 'strict'}

     

Log in to post a comment.