Comparison a LWORD variable with constants – Support Elsist https://support.elsist.biz/forums/topic/comparison-a-lword-variable-with-constants/feed/ Fri, 30 Oct 2026 08:47:24 +0000 https://bbpress.org/?v=2.6.20 it-IT https://support.elsist.biz/forums/topic/comparison-a-lword-variable-with-constants/#post-73730 Comparison a LWORD variable with constants https://support.elsist.biz/forums/topic/comparison-a-lword-variable-with-constants/#post-73730 Tue, 29 Aug 2023 09:26:40 +0000 Anonimo Trying to use LWORD type  variables in a function,i found out that the  operation comparison with zero literal results error. If I determine it as a typed literal (LWORD#0) the result is correct.

I don’t know if it is a bug or not.

]]>
https://support.elsist.biz/forums/topic/comparison-a-lword-variable-with-constants/#post-73733 Rispondi a: Comparison a LWORD variable with constants https://support.elsist.biz/forums/topic/comparison-a-lword-variable-with-constants/#post-73733 Tue, 29 Aug 2023 09:33:00 +0000 Sergio Bertana Currently the LogicLab compiles the comparisons considering the constants as a DWORD (32 bits), so without any type declaration only the first 32 bits of the LWORD variable are compared, please refer to the following example.

VAR
    MyLW : LWORD;
    MyResult : ARRAY[0..3] OF BOOL;
END_VAR

    // TRUE  IF MyLW=16#0000000000000000
    // TRUE  IF MyLW=16#0000000100000000
    // FALSE IF MyLW=16#0000000010000000

    MyResult[1]:=TO_BOOL(MyLW = 0);

    // FALSE IF MyLW=16#0000000000000000
    // FALSE IF MyLW=16#0000000100000000
    // TRUE  IF MyLW=16#0000000010000000

    MyResult[0]:=TO_BOOL(MyLW <> 0); 

    // TRUE  IF MyLW=16#0000000000000000
    // TRUE  IF MyLW=16#0000000100000000
    // TRUE  IF MyLW=16#0000000010000000

    MyResult[3]:=TO_BOOL(MyLW = LWORD#0);

    // FALSE IF MyLW=16#0000000000000000
    // TRUE  IF MyLW=16#0000000100000000
    // TRUE  IF MyLW=16#0000000010000000

    MyResult[2]:=TO_BOOL(MyLW <> LWORD#0);

// [End of file]

As you can see in the example to obtain correct result L’WORD# must precede the constant declaration. I will ask to Axel if in the future some modifications will be done.

]]>