<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Enumeration with 'strict' attribute</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/3594c46f09/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/3594c46f09/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/3594c46f09/</id><updated>2020-02-27T13:55:01.014000Z</updated><subtitle>Recent posts to Enumeration with 'strict' attribute</subtitle><entry><title>Enumeration with 'strict' attribute</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/3594c46f09/?limit=25#da4d" rel="alternate"/><published>2020-02-27T13:55:01.014000Z</published><updated>2020-02-27T13:55:01.014000Z</updated><author><name>timvh</name><uri>https://forge.codesys.com/u/timvh/</uri></author><id>https://forge.codesys.com1dc0ebb594505b39088bd0d38a435dfc65bef7f0</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;See the CODESYS Help:&lt;/p&gt;
&lt;p&gt;NOTICE!&lt;br/&gt;
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 &amp;gt;=3.5.7.0 , this causes compile errors in the following cases:&lt;/p&gt;
&lt;p&gt;Arithmetic operation with variables of the enumeration type&lt;br/&gt;
Assignment of a constant value to a variable of the enumeration type, in which the constant does not correspond to an enumeration value&lt;br/&gt;
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&lt;br/&gt;
The attribute can also be added explicitly or removed.&lt;/p&gt;
&lt;p&gt;Syntax: {attribute 'strict'}&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Enumeration with 'strict' attribute</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/3594c46f09/?limit=25#c54f" rel="alternate"/><published>2020-02-27T13:55:00.414000Z</published><updated>2020-02-27T13:55:00.414000Z</updated><author><name>Mikado</name><uri>https://forge.codesys.com/u/mikado/</uri></author><id>https://forge.codesys.com646ea84c0e96cf54aa7463be536070cee94de09e</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;strong&gt;Bump&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Was does {attribute 'strict'} do and can it be used outisde enums?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Enumeration with 'strict' attribute</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/3594c46f09/?limit=25#25ed" rel="alternate"/><published>2020-02-27T13:55:00.215000Z</published><updated>2020-02-27T13:55:00.215000Z</updated><author><name>rickj</name><uri>https://forge.codesys.com/u/rickj/</uri></author><id>https://forge.codesys.com39741325b8a1cfafa98f186730c2aee49bd66449</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;You could try using the instance name&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Zitat:&lt;/strong&gt;&lt;br/&gt;
e := SEL(x, e.green, e.red);&lt;/p&gt;
&lt;/blockquote&gt;&lt;/div&gt;</summary></entry><entry><title>Enumeration with 'strict' attribute</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/3594c46f09/?limit=25#3c1e" rel="alternate"/><published>2020-02-27T13:54:59.989000Z</published><updated>2020-02-27T13:54:59.989000Z</updated><author><name>swtroelofs</name><uri>https://forge.codesys.com/u/swtroelofs/</uri></author><id>https://forge.codesys.comc1b3b672aa25bf6debf0ea838e5af3577acc303d</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi everybody,&lt;/p&gt;
&lt;p&gt;I declare the following enumeration:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;{&lt;/span&gt;&lt;span class="n"&gt;attribute&lt;/span&gt; &lt;span class="s1"&gt;'strict'&lt;/span&gt;&lt;span class="err"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;TYPE&lt;/span&gt; &lt;span class="n"&gt;myEnum&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;red&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;yellow&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;green&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;END_TYPE&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Does anybode know the exact function of the Strict attribute? &lt;/p&gt;
&lt;p&gt;And why does this code not compile:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;PROGRAM&lt;/span&gt; &lt;span class="nt"&gt;myPOU&lt;/span&gt;
&lt;span class="nt"&gt;VAR&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="nt"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nd"&gt;BOOL&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="nt"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nd"&gt;myEnum&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;span class="nt"&gt;e&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;SEL&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;x&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;myEnum&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;green&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;myEnum&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;red&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;I get this error:&lt;br/&gt;
C0358:  'SEL(x, myEnum.green, myEnum.red)' is not a valid value for strict ENUM type 'myEnum'&lt;br/&gt;
When I remove the 'strict' attribute, the code compiles normally.&lt;br/&gt;
Any ideas? Thanks!&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>