Warning: Using embedded function blocks in functions can lead to unexpected behavior

Anglebert

Member
Join Date
Apr 2021
Location
Bulawayo
Posts
19
Hi,

I'm getting a bunch of these warnings when I build the program in Connected Components Workbench. The program is legacy code. The program runs fine but I cannot clear these warnings without changing the program structure. Should I be worried:confused::confused:?
 
Yes. Check if the function blocks maintain state between consecutive calls. If they don't, then you might be fine. But there still is something wrong in the design of your code.

One fundamental difference between function and function block is that the latter maintains state between consecutive calls. If your function block does not require this, then you could (and should) have used a function instead.

Variables declared inside a function do not maintain state between consecutive calls of the function. If the function blocks inside the function require state to be maintained between two calls then your code may not behave as you would expect.

I apologize if the above is confusing. It is somewhat difficult to describe this in a meaningful way if you don't have a good understanding of the underlying conceptual differences between functions and function blocks. Even more so since English is not my mother tongue, I am not a native speaker.
 
Even more so since English is not my mother tongue, I am not a native speaker.

+1 your English is very good. I tutor ESL and it is fine. Somewhat OT I guess, but anyway you have no reason to apologize. Have a great week!!
 
Thank you very much Toine for the explanation.

I have understood your point, that User Defined Function blocks are best used in situations where you would like to maintain/save the state. This raises another question for me, what is the best place to call a function block within a program, should I call them within the main program block and avoid calling them within functions?. How best should I structure my program when dealing with function blocks, thank you...

Your English is excellent, we are both not native speakers so don't worry....
 
The only meaningful thing I can say about that in this context is that function blocks should not be called from inside a function, since a function cannot be relied upon to maintain state between calls. Now which way to go from here depends entirely on what is going on in your function and the function blocks inside.

If you do have function blocks inside a function, there are two ways you can go to resolve the potential issues. Which way to go cannot be determined without looking into the details of the function and the function block(s) inside it.

Either the function block actually does not store state between calls. In that case it is not required to be a function block and should be rewritten to be a function instead.

Or the function block does require to maintain state between two calls. Then the function in which it is called should not have been a function so it should be rewritten into a function block.




Thanks saultgeorge and anglebert on the language. It is nice to know one is understandable (y)
 

Similar Topics

I am running Logix Designer v32, and noticed if I type new instruction value(s) (XIC, XIO, MOV, etc etc) into a rung without any operands/tags...
Replies
4
Views
734
Does anyone know of a timer that keeps accurate enough time to close a set of contacts for 30 seconds on the first Tuesday of the month for two...
Replies
7
Views
1,391
Hello. I am trying to use the Codesys function FILE.DirOpen from the CAA File library. For the eError output parameter I declare a CAA.ERROR type...
Replies
7
Views
2,585
We have a system based on Citect 7.4. and some energy meters are interfaced with this SCADA through egx300 Ethernet Gateway. I have interfaced an...
Replies
1
Views
1,327
Hi ... Everyone* I have this warning Cicode message : " possible missing operand between tags" when compile below code 👇...
Replies
2
Views
2,948
Back
Top Bottom