This is one of the things that really screwed my up when I first started using S7. In C and C++ there are no FBs. One can make the equivalent in C or C++ but they are not the same. The way parameters are passed is much different between FC and FB. The Berger books do not make that clear.
The IEC specification allows the compiler writer to pass parameters either way. So much for being standard.
I think it makes sense to use FBs whenever there is a need to remember state.
The user shouldn't need to be bothered by these details.
Good morning.
PeterW, thank you your constructive reply.
L D[AR2,P#0.0], Thank you for your supplement.
Peter Nachtwey, you explained what I want to say. thank you!
I also make program in C++ and C++/CLI (
Peter Nachtwey, you are right!). And I think it has better futures than S7. I wrote too many points, but I would like to make S7 program like C++. And I also bring general practices of C++ into S7. One of them is "Shorten the lifetime of the variables". According to this, if I can choose M, SharedDB, InstanceDB(STAT) or TEMP, I choose TEMP.
In C++ terms, I think FC is a function, and FB is a part of class.
PeterW, here is my answers (may be unsure for you, sorry.)
About No.3,4: I use Step7 V5.4. Instance DB has type of FB in symbol table, and editors(LAD and STL) checks FB and Instance DB at using CALL instruction. This is the reason "Instance DB has type".
I think Instance DB "should not" accessed except its FB. This should be "FB Private" data. But actually, they are public as PeterW pointed out. I don't prefer changing FB behavior by overwriting Instance DB from other logic blocks, it should be done by parameters to FB. I would like to apply "
High Cohesion - Low Coupling" principle to make program simple.
According to this, an UDT variable in instance DB should not used by other blocks except the FB calls other blocks.
About No.5: My example is not good, I'm sorry. I made function "Any memory areas" to "Any memory areas", because BLKMOV does not support Peripheral. When its parameter is "DB" to "DB", this future of FC is useful.
About No.6: I think logic block should be handled all parameters (except S7-Graph FB), because the caller block may be irresponsible for the state of STAT variables in FB. PeterW focuses "positive" side, and I focus "negative" side of this feature.