Adjustments in case of subsequent changes of the interface for a C-block or C++-block (deprecated)

If you change the already created interface of a C-block or C++-block after you have saved the ST-interface with {extern_c} or {extern_cxx} for the first time, you have to perform some adjustments. These adjustments differ – depending on the kind of the done change.

The name of a C-block or C++-block has been changed.

Observe the following, if you change the name of a C- or C++-function block or of a C- or C++-function, after you have saved the ST-interface with {extern_c} or {extern_cxx}:

Declaration within the ST-interface

Existing files after saving

Example: Original declaration
FUNCTION_BLOCK MyCFB
...
END_FUNCTION_BLOCK

for the block in C: LCfu___MyCFB.c and LCfu___MyCFB.hfor the block in C++: LCfu___MyCFB.cpp and LCfu___MyCFB.h

Example: Renamed declaration
FUNCTION_BLOCK TestMotor
...
END_FUNCTION_BLOCK

for the block in C: LCfu___MyCFB.c (a leftover from the original declaration), LCfu___TestMotor.c and LCfu___TestMotor.hfor the block in C++: LCfu___MyCFB.cpp (a leftover from the original declaration), LCfu___TestMotor.c and LCfu___TestMotor.h

Related to this example, perform the following steps:

  1. If you have already entered C-code or C++-code within the original file, copy this code from the file LCfu___MyCFB.c or LCfu___MyCFB.cpp into the file LCfu___TestMotor.c or LCfu___TestMotor.cpp.

  2. Delete the file LCfu___MyCFB.c or LCfu___MyCFB.cpp in the project explorer because it is no longer needed when the programming is loaded onto the PLC.


Background information: When saving the ST-interface with {extern_c} or {extern_cxx}, the C- or C++-file as well as the H-file are created for each function block and function. Already existing H-files are overwritten, already existing C-files or C++-files are not.

A declared C-block or C++-block has been deleted.

If you delete a declared C- or C++-function block or C- or C++-function, after you have saved the ST-interface with {extern_c} or {extern_cxx}, perform the following step:

Delete the C- or C++-file that is still listed for the deleted C-block or C++-block in the project explorer because it is no longer needed when the programming is loaded onto the PLC.

The variables and/or in-/outputs of a C-function or C++-function have been changed.

If you create new variables, in-/outputs or you delete/change the existing ones, you have to perform the following steps:

Changed interfaces for C-/C++-functions without performing the adjustments will cause errors when the programming will be loaded onto PLC.

If you do not perform the adjustments, the changed interface will not be considered when the programming will be loaded onto the PLC, instead of that errors will prevent the loading. Mind that the adjustments are required for C-functions or C++-functions only (they are not needed for C-function blocks or C++-function blocks).

  1. Double-click the file LCfu___name.c or LCfu___name.cpp from within the project explorer which has been created for the C-function or C++-function.

  2. In this file, select and copy the code that you have entered. Paste the copied code into any text file. This text file will be needed until the instructions are concluded.

  3. Delete the file LCfu___name.c or LCfu___name.cpp.

  4. Save the changed ST-interface with {extern_c} or {extern_cxx} so that the file LCfu___name.c or LCfu___name.cpp is created anew. Thus, this file contains the appropriate code for the changed interface.

  5. Copy the code that you have entered from the text file into the newly created file LCfu___name.c or LCfu___name.cpp.

  6. Save the modified file LCfu___name.c or LCfu___name.cpp. Delete the text file.

Background information:

  • In case of →function blocks, the interface is saved completely within the header file. As the header file is overwritten when the ST-interface with {extern_c} or {extern_cxx} is saved, there is no need for adjustments if the interface of a C-/C++-function block is changed.

  • In case of →functions, the interface is saved within the header file as well as within the C-/C++-file. There is no need for adjustments of the header file, if the interface of a C-/C++-function is changed. However, the C-/C++-file has to be adjusted as described above because an existing C-/C++-file is not overwritten when the ST-interface with {extern_c} or {extern_cxx} is saved.