Has anyone ever wanted a basic template support in Codesys? I mean, no recursive definitions, no compile time Turing completeness, just symbolic datatype declarations and POU generation.
I often find myself copypasting some POUs only to change datatypes, especially with array-based stuff and constrained memory/performances.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry, they're terms borrowed from C++, that has a very complex template system (in fact, it is a programming language itself embedded in another programming language).
It can perform any computation (an extremely crude definition of Turing completeness) at compile time (bounded only by compiler limitations), and support recursion (defining something in term of {an usually smaller version of} itself).
Anyway these are things that a PLC does not need to have in my opinion.
But being able to write something like
FUNCTION Frombulate<'T, 'U> : 'UVAR_INPUT input : 'T; a_1 : POINTER TO 'T; a_2 : POINTER TO 'U; a_size : USINT;END_VAR
where 'T and 'U denote types (either explicitly written or inferred at compile time), without resorting to ANY (which (1) is a PITA to use with arrays, (2) it's an endianness nightmare, (3) is a glorified UNION requiring runtime checking {that on a 48 MHz MCU has a more severe impact than on a Core i5}, and (4) does not work for output values anyway), would be great.
Last edit: sgronchi 2021-05-26
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Has anyone ever wanted a basic template support in Codesys? I mean, no recursive definitions, no compile time Turing completeness, just symbolic datatype declarations and POU generation.
I often find myself copypasting some POUs only to change datatypes, especially with array-based stuff and constrained memory/performances.
Could you add subtitles for the lesser informed;
Last edit: aliazzz 2021-05-26
Sorry, they're terms borrowed from C++, that has a very complex template system (in fact, it is a programming language itself embedded in another programming language).
It can perform any computation (an extremely crude definition of Turing completeness) at compile time (bounded only by compiler limitations), and support recursion (defining something in term of {an usually smaller version of} itself).
Anyway these are things that a PLC does not need to have in my opinion.
But being able to write something like
where 'T and 'U denote types (either explicitly written or inferred at compile time), without resorting to ANY (which (1) is a PITA to use with arrays, (2) it's an endianness nightmare, (3) is a glorified UNION requiring runtime checking {that on a 48 MHz MCU has a more severe impact than on a Core i5}, and (4) does not work for output values anyway), would be great.
Last edit: sgronchi 2021-05-26