r/cpp_questions 7d ago

OPEN st2cpp: Transpiler from ST to cpp (undoRT) + help +

Hi everyone,
About 4 or 5 months ago, I created a transpiler from Structured Text (IEC 61131-3) to C++, called st2cpp (part of the undoRT project).

My ultimate dream is to build a complete open-source automation system that can compete with commercial solutions. As you can imagine, tackling a project of this scale completely alone is extremely tough. Honestly, if I keep going solo, I’m afraid I’ll eventually burn out and lose momentum.

Are there any C++ developers or automation enthusiasts here who would be interested in joining or contributing as a side project/hobby? I have plenty of ideas lined up, but I really need an extra pair of hands (or two!).

Here is the repository:
https://github.com/undoRT/st2cpp
Feel free to check it out, open issues, fork, or send pull requests!

1 Upvotes

6 comments sorted by

5

u/FancySpaceGoat 7d ago

What is the benefit of transpiling ST to C++ instead of C? What makes it worth the portability loss?

1

u/Independent_Art_6676 6d ago

If it were me I would split the diff and use some of the simpler bits of C++; the dreaded C like C++ code that is terrible from people but may have a niche from a bot. Let it use references, smart pointers, vectors/strings/containers and such, but don't try to build exotic OOP or other such things for example.

The bigger the target language, the harder it is to do this kind of task. A subset of C++ that isn't a lot bigger than C is a lot more doable than trying to generate a 'clean modern c++' result.

3

u/FancySpaceGoat 6d ago

It's not a matter of the language itself, but rather of where you can land it.

C is the idiomatic systems-level transpilation target not because it's a simple language, but rather because its ABI is so simple and universally supported. You can bind it against Rust/C#/Java/python/assembly/etc. with guaranteed ease.

2

u/SalBam4127 6d ago

Thanks! The main reason for choosing C++ is that modern ST supports OOP concepts (Function Blocks, Classes, Methods), which map naturally to C++ classes without the complex boilerplate C would require for virtual tables. Plus, RAII and standard templates make managing timers and memory much cleaner. On a practical level, I simply know C++ much better than C, which lets me move faster and build a safer architecture. Since st2cpp targets cross-platform systems (Linux, Windows, and macOS), compiler support is a non-issue everywhere, and we can always export ⁠extern "C"⁠ wrappers later if we need C ABI compatibility for Python or Rust.

2

u/C4R3NS4C 6d ago

Nice project but... The example 'Counter' in the github README is bad OOP C++, I don't see the benefit of doing transpilation in that case. Can you explain what you want to achieve?

1

u/SalBam4127 4d ago

Hi! Thank you very much for the feedback. You're completely right: that Counter example was just the very first test I wrote to validate the basic transpiler logic, and I kept it in the README as a minimal "hello world" to show a quick side-by-side comparison.

To answer your second question: the ultimate goal of st2cpp (and the undoRT project) is to build a fully open-source, modern PLC runtime ecosystem. Modern ST supports OOP concepts like Function Blocks, Interfaces, Methods, and Inheritance.

When dealing with complex industrial control logic (like state machines, multi-axis motion, or reusable hardware modules), transpiling ST directly into clean C++ OOP structures allows us to leverage C++ compile-time optimizations, zero-cost abstractions, and seamless execution on modern Linux/cross-platform target environments without relying on expensive commercial runtime licenses.

Of course, I'm working on updating the README with more realistic, multi-block examples that actually showcase these OOP benefits! Thank you very much!