<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Compare operands of type STRUCT</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e3d1208273/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e3d1208273/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/e3d1208273/</id><updated>2020-02-27T13:52:51.889000Z</updated><subtitle>Recent posts to Compare operands of type STRUCT</subtitle><entry><title>Compare operands of type STRUCT</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e3d1208273/?limit=25#e14a" rel="alternate"/><published>2020-02-27T13:52:51.889000Z</published><updated>2020-02-27T13:52:51.889000Z</updated><author><name>PatrickT</name><uri>https://forge.codesys.com/u/patrickt/</uri></author><id>https://forge.codesys.comb74bdd8f18a6dd824d83bed7d0808ac0ec65a694</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Great, that's exactly what I need, thanks.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Compare operands of type STRUCT</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e3d1208273/?limit=25#cbba" rel="alternate"/><published>2020-02-27T13:52:51.704000Z</published><updated>2020-02-27T13:52:51.704000Z</updated><author><name>learnetk</name><uri>https://forge.codesys.com/u/learnetk/</uri></author><id>https://forge.codesys.com14b19a75ec4fa74ec2b158475333075ecbc5fb89</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi&lt;br/&gt;
not sure that you could still compare structure directly. But you could do it with pointers, using the Sysmemcmp function in library Sysmem. &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;pstruct1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;POINTER&lt;/span&gt; &lt;span class="n"&gt;TO&lt;/span&gt; &lt;span class="n"&gt;BYTE&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;pstruct2&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;POINTER&lt;/span&gt; &lt;span class="n"&gt;TO&lt;/span&gt; &lt;span class="n"&gt;BYTE&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

   &lt;span class="n"&gt;pstruct1&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;ADR&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;struct1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
   &lt;span class="n"&gt;pstruct2&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;ADR&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;struct2&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;IF sysmemcmp(pstruct1,pstruct2, SIZEOF(struct1)) &amp;lt;&amp;gt; 0 THEN&lt;br/&gt;
    testBool := TRUE;&lt;br/&gt;
ELSE&lt;br/&gt;
    testBool := FALSE;&lt;br/&gt;
END_IF&lt;/p&gt;
&lt;p&gt;something as above&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Compare operands of type STRUCT</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/e3d1208273/?limit=25#dac3" rel="alternate"/><published>2020-02-27T13:52:51.541000Z</published><updated>2020-02-27T13:52:51.541000Z</updated><author><name>PatrickT</name><uri>https://forge.codesys.com/u/patrickt/</uri></author><id>https://forge.codesys.com8e329824ac719d6e347d0963deb961f6671a895f</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;The following Help section for Data Type &amp;gt; Structure implies that it is possible to compare structures: &lt;/p&gt;
&lt;p&gt;"If the target system supports the data type, as from compiler version &amp;gt;= 3.5.7.0 you can compare operands of type STRUCT (structure). Example: IF (stStruct1 := stStruct2) THEN...." . &lt;/p&gt;
&lt;p&gt;(I assume this is a typo and should read IF (struct1 = struct2) THEN ...)&lt;/p&gt;
&lt;p&gt;Using Control Win V3 Version 3.5.7.10, I have:&lt;/p&gt;
&lt;p&gt;TYPE TestDUT :&lt;br/&gt;
STRUCT&lt;br/&gt;
    MyInt: INT;&lt;br/&gt;
END_STRUCT&lt;br/&gt;
END_TYPE&lt;/p&gt;
&lt;p&gt;VAR&lt;br/&gt;
    struct1: TestDUT;&lt;br/&gt;
    struct2: TestDUT;&lt;br/&gt;
    testBool: BOOL;&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;p&gt;IF (struct1 = struct2) THEN&lt;br/&gt;
    testBool := TRUE;&lt;br/&gt;
END_IF&lt;/p&gt;
&lt;p&gt;This generates the error:&lt;br/&gt;
Cannot compare type 'TestDUT' with type 'TestDUT'&lt;/p&gt;
&lt;p&gt;Have I made an error or is this feature not supported on the target system?&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>