ziga
ziga

Reputation: 390

Are there any cons to using TO_<type> conversion instead of <type>_TO_<type>?

TwinCAT and (I think so) every other IEC61131-3 language supports both conversion types <type>_TO_<type> and TO_<type>. I am wondering, is there any cons to using the latter, so TO_<type>? For example, I have a calculation and we all know, that typing the extra 5 letters makes or breaks your day ;)

nResult : INT;
fDivisor : REAL;

// Does this perform any slower, or are there any cons to using it like this?
nResult := TO_INT(32767.0/fDivisor);
nResult := REAL_TO_INT(32767.0/fDivisor);

Upvotes: 3

Views: 262

Answers (1)

Quirzo
Quirzo

Reputation: 1425

I have used only the shorthand functions TO_REAL() etc. for last 1-2 years without any issues. They simplify the code alot and you don't need to write so much code.

I'm 99% sure that there are no cons / performance issues for the PLC runtime, as the compiler most probably just automatically checks the data type during compilation.

I haven't measured the performance, but the only downside I can think of is that the compiler needs to check some data types during compilation. However, when usin X_TO_Y() conversion, the compiler still checks the data type and gives a warning/error if needed.

Upvotes: 1

Related Questions