Codesys syntax program

Hello,

Do you know why this command with parenthesis doesn’t work

IF (arrStruct[j].R_index_courant)>(arrStruct[j+1].R_index_courant) THEN

and this one without parenthesis works :

IF arrStruct[aiIndexArray[j]].R_index_courant > arrStruct[aiIndexArray[j+1]].R_index_courant THEN

Another thing strange:

image

in that program PuissABC is an int and divided with a real , and it works !! why ?

Just guessing: Putting something inside of parenthesis may be seen by the compiler as a whole condition. In your case you have created two independent conditions separated by “>”. Proper syntax using parenthesis (although not needed) would be …

IF (arrStruct[aiIndexArray[j]].R_index_courant > arrStruct[aiIndexArray[j+1]].R_index_courant) THEN

Thanks for your explanation

and for the second one, codesys should give you a warning about an automatic type conversion no ?

Hello,

there is no warning and the program compile.

The calculation is done 1 time every each second , as you can see it below.

NRJ_ABC is a REAL right ? if you divide a INT by a REAL, you will have an automatic conversion from the INT to REAL without any WARNING as long as the output is also a REAL.

thank you for the explanation ,

i didn’t know that automatic conversion.

s there any other case that automatic conversion can apply ?

word , dword and so on..

Any conversion from a type to a bigger type will be without warning:
USINT → UINT → UDINT → ULINT
SINT → INT → DINT → LINT
BYTE → WORD → DWORD → LWORD
REAL → LREAL
Also conversion from USINT→BYTE since those 2 contain the same data.
there is maybe more than that but i can’t remember it …