I am new here. Pointers are a tool I use very often. Without them, I feel limited in so many ways. Is there pointer data type support and I just cannot find it or there is none?

If there is none, is it a planned feature?
Quote 0 0
Pointers are for low level languages like C. IEC 61131-3 is a type-safe high level language, and therefore has no pointers (just like Python, Java, and some other high level languages)
Quote 0 0
Well, I am not sure. I have standard draft  61131-3—2016 and in paragraph it includes pointers in the standard. С is also a high-level language and it has pointers. Unfortunately, I have Russian version of the draft, but here it is. You can see REF_TO and REF() defined in the standard. 


Anyway, even if those are not in the standard, pointers are way important. They are in Codesys, logi.CAD3, TwinCAD, and other IDEs. Because it is obvious that pointers are important in controllers programming. I think we need to implement them then. Especially that it should not be that difficult as С has pointers already and it should not be difficult.

I discovered this openPLC project just recently. And first I thought that i"ve found pure gold. But when I discovered no pointers I was disappointed, because I cannot create ST program without them.
Quote 0 0
Is there any chance that pointers will be supported? Based on the post here:
The matiec compiler already supports pointers, following the syntax defined in IEC 61131-3 edition 3.
Quote 0 0
I had a private conversation with user lc625 (Carsten) about this topic a few months ago. I managed to create a beta version of the editor that had some form of pointer implemented. Unfortunately I don't have any free time available to work further on the development of this feature for now. I believe it is not hard to finish, might just require some debugging and working on little details. I'll leave some parts of the conversation here so that anyone that is interested can continue the work where I left off.
thiagoralves wrote:

Hey Carsten, how are you doing?

So, I'm working on incorporating your great work with the OSCAT library on the next version of the OpenPLC Editor and runtime. I've completed integrating OSCAT Building 1.0 and it works great! Thanks =)

Now, the problem that I'm facing is that, while I try to incorporate OSCAT Mathematics, there are several blocks in that library that are already defined in OSCAT Building. What should I do about those? Should I remove the redundant blocks from one of the libraries? Is the implementation different between OSCAT Building and OSCAT Mathematics?


Thiago Alves

PS: Also, I'm also working on adding some new features to the core compiler (matiec) that will allow you to continue your work on the libraries. Things that are on the works:
- display full token location on error messages
- use a relaxed datatype equivalence model
- allow use of references (REF_TO, REF, ^, NULL) as well as REF_TO in ARRAYs and STRUCTs
- allow use of nested comments
- allow use of forward references

lc625 wrote:

Hi Thiago,

nice to get a message from you! I’m fine and hope it’s the same with you.


The second thing is the missing functionality of using pointers. Obviously there is a solution already:
"Carsten, please note that the underlying matiec compiler already supports pointers, following the syntax defined in IEC 61131-3 edition 3.
I implemented this quite some time ago upon request by a company using matiec but not Beremiz. You need to add a command line option to have the compiler accept this syntax.
Running ./iec2c will list all available options. Let me see now...
-r : allow use of references (REF_TO, REF, ^, NULL) (an IEC 61131-3 v3 feature)
-R : allow use of REF_TO ANY datatypes (a non-standard extension!) as well as REF_TO in ARRAYs and STRUCTs (a non-standard extension!)

Does this help?

Thiago, if there is a way to help you with the implementation, please let me know. If there are things to do with my basic skills, I will do my best.

Hope to hear you soon


thiagoralves wrote:

Carsten, here is the link for you to download the beta version of the editor:

This should have the entire building library as you have implemented it in the project, and the modifications to support REF_TO (simulation mode only)

lc625 wrote:

Hi Thiago,
great job, really impressive. If all the blocks are implemented, i fear you have to write a new manual for your project :-) To be honest, I think it will be one of the most powerful PLC software available.
Let's take a brief look towards the pointer functionality:
I tried to convert one block which uses a pointer. I just choose one randomly. The pictures are showing you the original CODESYS code and the OpenPLC trial. I expected to find any datatypes or possibilities to create own datatypes related to pointers. Unfortunately I couldn't find any. The "ADR" function should be a standard one but is obviously not known.
image (1).png 
Looking at iec2c there is obviously the possibility of using pointers. I suppose the syntax is not "pointer to" but "rev to". The desired option might be -r; -R.
image (2).png 
At this point I come to an end. For me it's like trying to fly to the moon without having invented the wheel.

Of course this is not an A theme. It's more a wish to complete the library. Do you have an idea without investing too much time?

thiagoralves wrote:

Thanks. MatIEC (OpenPLC's internal compiler) supports similar instructions. POINTER TO BYTE should be translated as REF_TO BYTE. The ADR() function should be translated as REF(). I still need to implement the menu on the editor where you will be able to pick REF_TO types. However, if you declare the variables manually it might work on the compiler (like, create the VAR section by hand in the code)

lc625 wrote:

Hi Thiago,
I found a few minutes this evening. I'm not sure if the REF and REF_TO thing works until now. To show you at first the original code:
image (3).png 
Next the code in OpenPLC
image (4).png 
At last the error message
image (5).png 

If I can try something else, let me know

Quote 1 0